UNPKG

blockchain-link

Version:

Link - The Blockchain File Sharing Protocol

57 lines (44 loc) 1.15 kB
// Generated by CoffeeScript 1.6.3 (function() { var Semaphore, ThreadBarrier, __slice = [].slice; ThreadBarrier = (function() { function ThreadBarrier(parties, block) { this.parties = parties; this.block = block; } ThreadBarrier.prototype.join = function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; --this.parties; if (this.parties < 1) { return this.block.apply(this, args); } }; return ThreadBarrier; })(); Semaphore = (function() { function Semaphore() { this.waiting = []; this.inUse = false; } Semaphore.prototype.acquire = function(block) { if (this.inUse) { return this.waiting.push(block); } else { this.inUse = true; return block(); } }; Semaphore.prototype.release = function() { if (this.waiting.length > 0) { return this.waiting.shift()(); } else { return this.inUse = false; } }; return Semaphore; })(); exports.ThreadBarrier = ThreadBarrier; exports.Semaphore = Semaphore; }).call(this);