Skip to content

@mkuklis /gist:1350255
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
multiplexCallback = (function () {
var callbacks = {};
return function(callbackable, callback) {
var callbackList = callbacks[callbackable] || [];
callbackList.push(callback);
if (!callbacks[callbackable]) {
callbacks[callbackable] = callbackList;
callbackable(function () {
for (var i = 0, l = callbackList.length; i < l; i++) {
callbackList[i]();
}
// delete processed callbacks
delete callbacks[callbackable];
});
}
};
})();
// same thing but different approach
// attaching callbacks directly to collbackable
function multiplexCallback (callbackable, callback) {
if (!callbackable.list) {
callbackable.list = [];
callbackable.list.push(callback);
callbackable(function () {
for (var i = 0, l = callbackable.list.length; i < l; i++) {
callbackable.list[i]();
}
// delete processed callbacks
delete callbackable.list;
});
} else {
callbackable.list.push(callback);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.