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

Reply via email to