Promise not working


function wait(ms) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            console.log('before resolve');
            console.log('after resolve');
        }, ms);

wait(1000).then(() => { // first async call
    console.log('done 1');
    return wait(1000);  // second async call
}).then(() => {
    console.log('done 2');

Nothing will be print and no error is shown.
Have any idea about this?

Isn’t setTimeout a window method? If so, I’d say you don’t have a window object to work with as you are not in a browser.

1 Like

It is clear for a beginner.
Thanks a lot.

NodeJS implements it as well, it could be a good idea to add it for compatibility with libraries and existing code

@simonbs is probably already working on it

Yes, I’m working on this a little on and off right now. My first implementation had some issues so I’ll have to try out something else.

For the record, and until Simon has come up with something better, I have a rough and ready working wait-ish module over here.