Created
February 20, 2014 20:46
-
-
Save kriskowal/9122872 to your computer and use it in GitHub Desktop.
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
var Qeueue = require("q/queue"); | |
var semaphore = new Queue(); | |
semaphore.put(); // once for one job at a time | |
function exclusive(method) { | |
return function wrapped() { | |
var self = this, args = Array.prototype.slice.call(arguments); | |
return semaphore.get() | |
.then(function () { | |
return method.apply(self, args); | |
}).finally(semaphore.put); | |
}; | |
}; | |
var a = exclusive(a); | |
var b = exclusive(b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment