Task Init

This commit is contained in:
teslim
2025-02-11 15:06:41 +01:00
parent 0241fcc579
commit f52cec4cf1
1718 changed files with 91042 additions and 5 deletions
+49
View File
@@ -0,0 +1,49 @@
"use strict";
/**
* This is apparently a bit like a Jquery deferred, hence the name
*/
class Deferred {
constructor(Promise) {
this._state = Deferred.PENDING;
this._resolve = undefined;
this._reject = undefined;
this._promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
get state() {
return this._state;
}
get promise() {
return this._promise;
}
reject(reason) {
if (this._state !== Deferred.PENDING) {
return;
}
this._state = Deferred.REJECTED;
this._reject(reason);
}
resolve(value) {
if (this._state !== Deferred.PENDING) {
return;
}
this._state = Deferred.FULFILLED;
this._resolve(value);
}
}
// TODO: should these really live here? or be a seperate 'state' enum
Deferred.PENDING = "PENDING";
Deferred.FULFILLED = "FULFILLED";
Deferred.REJECTED = "REJECTED";
module.exports = Deferred;