The Done callback
What is the done
callback and why is it important?
Problem
Concurrent Tasks is a JavaScript module, which runs multiple tasks concurrently until all the tasks are complete. It needs a way to figure out when a particular task has been completed.
Solution
Gulp solves this problem by either accepting a return of a Gulp task, or by calling a function done. Similarly, to solve the exact same problem, each task passed to the TaskRunner has access to a special function called done
(ingenuity max).
Purpose
The purpose of this function is simple: Tell the instance when a particular task is complete!
Internally, the done function does a fair amount of work:
- Makes a free slot available for the internal runner
- Updates completion counts and calls the internal runner
- Updates the time elapsed from start, until the function calling done’s completion
- Calls the internal runner to pick up the next task in the queue
Examples
It’s a very simplistic approach, which can be used across anything. Be it functions, Promises, timeouts etc.