UNPKG

@victorequena22/utiles

Version:

Utilidades para mi uso que pongo a dispocion

42 lines (41 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.semaforo = void 0; class Semaforo { constructor() { this.turnos = []; this.index = 0; this.block = true; this.add = this.add.bind(this); this.next = this.next.bind(this); this.clean = this.clean.bind(this); this.isTurn = this.isTurn.bind(this); } add(t) { this.turnos.push(t); } clean(t) { this.turnos = this.turnos.filter(r => r !== t); if (this.index >= this.turnos.length) this.index = 0; } isTurn(t) { if (this.block && this.turnos[this.index] === t) { this.block = false; return true; } return false; } forceTurn(t) { this.index = this.turnos.findIndex(s => s === t); } next() { this.block = true; this.index++; if (this.index >= this.turnos.length || this.index < 0) this.index = 0; } } const se = new Semaforo(); function semaforo() { return se; } exports.semaforo = semaforo;