UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

57 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PowerSwitch = void 0; class PowerSwitch { constructor() { this.isPowered = false; this.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; } } exports.PowerSwitch = PowerSwitch; //# sourceMappingURL=power-switch.js.map