documentcloud/underscore — pull request #366 by tillberg (2011-11-10 17:44:26+00:00)
Title: This commit fixes #364

I've implemented this fix for #364. I've run into the same issue myself several times just this week. The typical usage pattern I use looks like (same idea as yuchi's, but boiled down ;) ):

```javascript
function doSomethingToArray(items, cbWhenDone) {
if (items.length === 0) {
cbWhenDone();
} else {
var cbDoneWithOne = _.after(items.length, cbWhenDone);
_.each(items, function(item) {
doSomethingAsync(item, cbDoneWithOne);
});
}
}
```

This change cuts out that whole if/else block, a la:

```javascript
function doSomethingToArray(items, cbWhenDone) {
var cbDoneWithOne = _.after(items.length, cbWhenDone);
_.each(items, function(item) {
doSomethingAsync(item, cbDoneWithOne);
});
}
```

Are there any use cases that this change will break?

Another possible solution would be for yuchi and I to discover https://github.com/caolan/async or some similar library that solves these async use cases properly. (I just discovered it while searching issue history on this and found #114)