A promise that resolves after a delay.
C. Scott Ananian
ecmascript at cscott.net
Wed Feb 3 21:18:27 UTC 2016
Here's a quick plug for my `prfun` library (https://github.com/cscott/prfun)
which implements this as `Promise.delay(1000)`.
You can also do `return somepromise.delay(100)` which resolves to the same
value as `samepromise`, just 100 ms later.
On Wed, Feb 3, 2016 at 4:03 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> Chiming in just to underline that setTimeout and setInterval accepts extra
> arguments since about ever so that the following is eventually all you need.
> new Promise(r => setTimeout(r, 1000));
> new Promise(r => setTimeout(r, 1000, "some value"));
> Best Regards
> On Wed, Feb 3, 2016 at 8:51 PM, JD Isaacks <jd at jisaacks.com> wrote:
>> I think it would be super useful to be able to do something like:
>> Promise.after(1000).then( /* cb */ );
>> and have the promise resolve after 1000 milliseconds.
>> The promise would just resolve with the same value (in this case 1000)
>> but could easily delay resolving another value like so:
>> Promise.after(1000).then(() => "other value");
>> instead of currently having to use a setTimeout:
>> new Promise(resolve => setTimeout(() => resolve("some value"), 1000));
>> I believe Promise.after would be so much more readable and useful.
>> I am not sure if the name `after` is the best name, `wait`, `when`,
>> `sleep` are possible names or maybe there is a better name I haven't even
>> thought of.
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss