Skip to content

Instantly share code, notes, and snippets.

View Dellos7's full-sized avatar

David López Castellote Dellos7

View GitHub Profile
@Dellos7
Dellos7 / semaphore.js
Created January 31, 2019 12:10 — forked from gregkorossy/semaphore.js
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}