Echo JS 0.11.0

<~>
tracker1 2755 days ago. link 1 point
again.. not sure why this is so hard to spread...

    const sleep = ms => new Promise(res => setTimeout(res, ms));
    ...
      await sleep(10000);

Replies

MaxArt 2755 days ago. link 1 point
Would be nice to have a `wake` function that cancels the timeout, rejecting the promise. Something like Angular's $timeout.
But I guess you need at least a bunch of lines for that.
xab 2754 days ago. link 1 point
Cancellable promises would be nice, to be exact. It's not the timeout that hurts for me, but the fetch.
MaxArt 2754 days ago. link 1 point
Indeed, it's one of the main arguments about the future development of JS promises.

Also, `setTimeout` should be updated to become a promise (alas, won't happen because `setInterval` can't be promisified too).
xat 2754 days ago. link 3 points
Maybe Promises are just the wrong tool for this kind of stuff in general. 

Interestingly it would be no problem solving these problems with Observables. Cancelation can be done with `dispose` and  setInterval would also be trivial to implement.
xat 2755 days ago. link 1 point
I agree on that. In about 30% of the cases, that I use setTimeout, there is some cancelation logic involved (polling, debounce etc.).