Promise-returning delay function
domenic at domenicdenicola.com
Mon Sep 8 16:13:39 PDT 2014
Spinning off a new thread...
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Mark S. Miller
Subject: RE: "use strict" VS setTimeout
> Let's just be sure that we avoid this mistake when promises grow something like Q's Q.delay. Promise.delay? Promise.prototype.delay?
IMO this should be a utility function that uses promises, not a feature of promises/promise classes themselves. So it would be e.g. `global.delay` or `import delay from "js/flow"` or something. I think in general promise utility functions are a slippery slope and I'd feel more comfortable sliding down that slope if we kept them in a module instead of grafting them onto the class itself. I'd rather reserve that for things that are core to the promise experience, either control-flow wise (`Promise.prototype.finally`, perhaps `Promise.any`) or for pipelining (`.get`, `.call`, etc.).
BTW I definitely agree that promise-returning `delay(ms)` as a better `setTimeout` should be part of the standard library.
(I also find the name `sleep` somewhat attractive, as a re-appropriation from threaded contexts. `await sleep(1000)`, heh.)
More information about the es-discuss