Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created February 20, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kriskowal/9122872 to your computer and use it in GitHub Desktop.
Save kriskowal/9122872 to your computer and use it in GitHub Desktop.
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