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.
If it's the part I'm thinking of - where make app a function or not:
app = () => new Task((rej, res)... app().fork
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.
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.
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.