The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Use Task for Asynchronous Actions

Use Task for Asynchronous Actions

3:46
We refactor a standard node callback style workflow into a composed task-based workflow.
Watch this lesson now
Avatar
egghead.io

We refactor a standard node callback style workflow into a composed task-based workflow.

Avatar
Egghead

Hi, at the end of video you say one solution uses 'new' Task and other solution uses 'old' Task, can you elaborate a little bit, thanks.

Avatar
Brian Lonsdorf

Hi!

If it's the part I'm thinking of - where make app a function or not:

app = () => new Task((rej, res)...
app().fork

vs

app = new Task((rej, res)...
app.fork

The idea is the former is a function that creates a new Task object instance each time you call it and the other is just assigned to the Task instance itself.

Since Task is lazy, it doesn't actually run until we fork it. That means we don't need to put it in a function wrapper to prevent it from running.

In reply to Egghead
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?