DEV Community

Discussion on: Simplify code by promisifying `setTimeout`

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I'd use the chance to change the time argument to use seconds because who the fuck thought milliseconds were acceptable?

Collapse
 
puruvj profile image
PuruVJ

You can sure change it. What Mark suggested would work.

However, I disagree with your point. I've used more timers less than 1 second or timeouts like 1.5 seconds that I kinda find the milliseconds method better. Plus its so standard thanks to langs like Java and C and our own JS that any API respecting seconds would feel plain weird

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I've used more timers less than 1 second or timeouts like 1.5 seconds

What's the problem with sleep(1.5)? I still find that more natural than sleep(1500)

Plus its so standard

No it's not. C uses seconds, the linux command-line program sleep also uses seconds... There's lots of examples out there and milliseconds is far from common.

The only two differences are:

  1. Seconds are the SI base unit.
  2. Seconds are within the orders of magnitude that humans can perceive.

I'd say both of those are clearly benefits of using seconds.

Thread Thread
 
puruvj profile image
PuruVJ

Well, you have a point.

However having seconds measurement in a language that puts milliseconds as first class citizens would incur the cost of context switching.

Thanks for the info

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

The context switching is precisely why I want this. If you're dealing with seconds in the backend but have to constantly switch to thinking in milliseconds for the frontend code, that's mental work I could spend thinking about the actual code.

Collapse
 
markwitt_me profile image
Mark Witt

Change setTimeout(resolve, time) to setTimeout(resolve, time * 1000)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Yes, thanks but I was already well aware of how to convert milliseconds to seconds ;D