Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 833 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!

Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.

Use Task for Asynchronous Actions

3:46 JavaScript lesson by

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

Get the Code Now
click to level up

egghead.io comment guidelines


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


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.

Brian Lonsdorf


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

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


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

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

Hi Brian,

Thanks for response.

I understand now, other question that I have is you could use Promises, right, instead of 'Task' library.
Is there difference between those two, because I use Promises in the same way as Task is used here.

In reply to Brian Lonsdorf
Brian Lonsdorf

Promises are eager, which means they are not pure - they will immediately run side effects upon construction. Task will allow you to work with values as though they were there, but it does not run until you tell it with fork() - usually outside your pure application.

In reply to Egghead
Joel's Head
Why are we asking?