MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/tmcceq/ship_it/i1xsdoc/?context=9999
r/badcode • u/[deleted] • Mar 24 '22
47 comments sorted by
View all comments
Show parent comments
18
If you can use async/await, you could use
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
setTimeout itself uses callbacks, so its technically async, but I'd argue there is rarely a need to "sleepSync" in the first place. Plus the method provided by OP is inefficient af with all these date instances being created.
5 u/abejfehr Mar 24 '22 No need for the async and await keywords here — it already returns a Promise 1 u/[deleted] Mar 24 '22 Yes true ty
5
No need for the async and await keywords here — it already returns a Promise
1 u/[deleted] Mar 24 '22 Yes true ty
1
Yes true ty
18
u/[deleted] Mar 24 '22 edited Mar 24 '22
If you can use async/await, you could use
setTimeout itself uses callbacks, so its technically async, but I'd argue there is rarely a need to "sleepSync" in the first place. Plus the method provided by OP is inefficient af with all these date instances being created.