It's year 2018 and modem node is of version 9 or 10, i.e., the accepted answer from How Can I Wait In Node.js in year 2013 is no good any more. Hence I'm asking it again, as per the guidance of meta here.
The criteria for the answer now is to use existing ES6 and Node.js v9+ features without any extra packages.
I found the answer from @treecoder at https://stackoverflow.com/a/44036791/2125837 particular interesting, but I just can't make it work for my case:
$ node
> const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
> const waitThenDo = async (howLong, doWhat) => await sleep(howLong*1000).then(doWhat)
> waitThenDo(1, console.log(2))
2
Promise {
<pending>,
...
I.e., the waitThenDo
does the printing right away, without any delay.
What I've done wrong, and/or, what the best latest technology to wait/sleep?