1. 13
    Use Task for Asynchronous Actions
    3m 46s

Use Task for Asynchronous Actions

InstructorBrian Lonsdorf

Share this video with your friends

Send Tweet

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

Egghead
~ 8 years ago

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 Lonsdorfinstructor
~ 8 years ago

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.

Egghead
~ 8 years ago

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.

Brian Lonsdorfinstructor
~ 8 years ago

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.