@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
66 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlinkstickSync = void 0;
const blinkstick_1 = require("./blinkstick");
const transport_1 = require("../transport");
/**
* Synchronous version of BlinkStick class.
* @category Core
*/
class BlinkstickSync extends blinkstick_1.BlinkStick {
constructor(device) {
super(new transport_1.NodeHidSyncTransport(device));
this.isSync = true;
this.scheduledOperations = [];
}
/**
* Schedules an operation to be executed later.
*
* @param fn
*/
schedule(fn) {
this.scheduledOperations.push(fn);
return this;
}
async runScheduledOperations() {
if (this.scheduledOperations.length === 0) {
return;
}
do {
const operation = this.scheduledOperations.shift();
if (operation) {
await operation(this);
}
} while (this.scheduledOperations.length > 0);
}
/**
* @ignore
*/
async setColor(...args) {
await this.runScheduledOperations();
return super.setColor(...args);
}
/**
* @ignore
*/
async getColor(...args) {
await this.runScheduledOperations();
return super.getColor(...args);
}
/**
* @ignore
*/
async getColors(...args) {
await this.runScheduledOperations();
return super.getColors(...args);
}
/**
* @ignore
*/
async setColors(...args) {
await this.runScheduledOperations();
return super.setColors(...args);
}
}
exports.BlinkstickSync = BlinkstickSync;
//# sourceMappingURL=blinkstick.sync.js.map