Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
// TODO Anonymous names for event listeners. | ||
import {set} from "./schedule"; | ||
|
||
export default function() { | ||
var that = this, size = that.size(); | ||
var on0, on1, that = this, id = that._id, size = that.size(); | ||
return new Promise(function(resolve, reject) { | ||
that.on("cancel.end interrupt.end", reject).on("end.end", function() { | ||
if (--size === 0) resolve(); | ||
var cancel = {value: reject}, | ||
end = {value: function() { if (--size === 0) resolve(); }}; | ||
|
||
that.each(function() { | ||
var schedule = set(this, id), | ||
on = schedule.on; | ||
|
||
// If this node shared a dispatch with the previous node, | ||
// just assign the updated shared dispatch and we’re done! | ||
// Otherwise, copy-on-write. | ||
if (on !== on0) { | ||
on1 = (on0 = on).copy(); | ||
on1._.cancel.push(cancel); | ||
on1._.interrupt.push(cancel); | ||
on1._.end.push(end); | ||
} | ||
|
||
schedule.on = on1; | ||
}); | ||
}); | ||
} |