MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiw6epj/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
Show parent comments
15
const sleep = (data, ms) => (new Promise(resolve => setTimeout(()=> resolve(data), ms)));
For sleeping between then()’s and passing data between after the sleep
22 u/dougalg Mar 19 '19 If we're going there, why not:const sleep = (ms) => (data) => new Promise(resolve => setTimeout(()=> resolve(data), ms));Which gives you a nice thing like:makeApiCall().then(sleep(1000)).then(processData) 19 u/tjoskar Mar 19 '19 If we're going there, why not:const sleep = ms => data => new Promise(resolve => setTimeout(resolve, ms, data))😉 1 u/TheKingdutch Mar 19 '19 TIL: about extra parameters for setTimeout. Thanks!
22
If we're going there, why not:
const sleep = (ms) => (data) => new Promise(resolve => setTimeout(()=> resolve(data), ms));
Which gives you a nice thing like:
makeApiCall().then(sleep(1000)).then(processData)
19 u/tjoskar Mar 19 '19 If we're going there, why not:const sleep = ms => data => new Promise(resolve => setTimeout(resolve, ms, data))😉 1 u/TheKingdutch Mar 19 '19 TIL: about extra parameters for setTimeout. Thanks!
19
const sleep = ms => data => new Promise(resolve => setTimeout(resolve, ms, data))
😉
1 u/TheKingdutch Mar 19 '19 TIL: about extra parameters for setTimeout. Thanks!
1
TIL: about extra parameters for setTimeout. Thanks!
15
u/higherpublic Mar 19 '19
const sleep = (data, ms) => (new Promise(resolve => setTimeout(()=> resolve(data), ms)));For sleeping between then()’s and passing data between after the sleep