scriptonia

Dec 28 '11

mutex js gist

var Mutex = function() {
  this.queues = [];
  this.locked = false;
};
Mutex.prototype = {
  push: function(callback) {
    var self = this;
    this.queues.push(callback);
    if (!this.locked) {
      this.locked = true;
      var f = this.queues.pop();
      try {
        f(function() {
          self.locked = false;
        });
      } catch(ex) {
        self.locked = false;
      }
    }
  }
};
view raw mutex.js This Gist brought to you by GitHub.

12 notes View comments Tags: javascript js gist

  1. oivoodoo posted this
Blog comments powered by Disqus