In the first example, I haven't written this by accident: > also granting you args are those passed at the invocation time and no possible mutation capable of affecting `computeResult` could happen later on?
which is why I've shown both examples, the before `setTimeout(resolve, 1000, computeResult(...args));` and the after ;-) On Tue, Feb 28, 2017 at 8:02 PM, T.J. Crowder < [email protected]> wrote: > On Tue, Feb 28, 2017 at 7:47 PM, Andrea Giammarchi < > [email protected]> wrote: > > > > Why not using fill setTimeout API, also granting you args are those > passed > > at the invocation time and no possible mutation capable of affecting > > `computeResult` could happen later on? > > > > > > ```js > > > > const asyncFunc = (...args) => new Promise((resolve) => { > > > > setTimeout(resolve, 1000, computeResult(...args)); > > > > }); > > > > ``` > > That would call `computeReult` *before* the timeout fired, whereas > apparently it should be after the delay. > > Your second one, though, is nice and simple. Using Jérémy's `delay`, it > looks like this: > > ```js > const asyncFunc = (...args) => > delay(1000).then(() => computeResult(...args)); > ``` > > -- T.J. Crowder > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

