UNPKG

svcorelib

Version:

Core library used in the projects of Sv443 and the Sv443 Network. Contains tons of miscellaneous QoL features.

35 lines (29 loc) 820 B
class StatePromise { constructor(promise) { if(!(promise instanceof Promise)) throw new TypeError(`Wrong type provided in constructor of StatePromise - expected instance of "Promise" class`); /** @type {Promise} */ this.intPromise = promise; this.state = "initialized"; } exec() { this.state = "pending"; return new Promise((res, rej) => { this.intPromise.then((...args) => { this.state = "resolved"; return res(...args); }).catch((...args) => { this.state = "rejected"; return rej(...args); }); }); } getState() { return this.state; } } module.exports = StatePromise;