UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

51 lines 1.13 kB
export class PowerSwitch { isPowered = false; pendingState = null; switch(s) { if (this.pendingState !== null) { return false; } if (s === this.isPowered) { return false; } this.pendingState = s; return true; } isUp() { return this.isPowered; } isDown() { return !this.isPowered; } isGoingUp() { return this.pendingState === true; } isGoingDown() { return this.pendingState === false; } isRunning() { return this.isUp() && this.pendingState === null; } goingUp() { return this.switch(true); } goingDown() { return this.switch(false); } commit() { if (this.pendingState === null) { return false; } this.isPowered = this.pendingState; this.pendingState = null; return true; } rollback() { if (this.pendingState === null) { return false; } this.pendingState = null; return true; } } //# sourceMappingURL=power-switch.js.map