I've had to answer flow control issues repeatedly. Both in my own code-base and as answers to StackOverflow questions. All these problems can be handled with one of two methods. One issue is dealing with nested asynchronous tasks and the answer to this is to use middleware. The other issue is aggregating many asynchronous tasks into one end point and the answer is this is to use function execution delay.
I've build a tiny utility function called [after][1] to handle aggregating of asynchronous tasks. I'll walk you through how to use it in this post. I will get [around to][4] building a generic middleware component that can be used to chain asynchronous tasks together effectively, it will be inspired by connect.
Let's start with a description of after
. Below is an illustrated example of using it
// Create a single end point to aggregate two asynchronous tasks into.
var cb = after(2, function _allFinished(file1, file2) {