mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-19 12:37:05 +00:00
28 lines
705 B
JavaScript
28 lines
705 B
JavaScript
export default class BaseOperation {
|
|
static STATUS_PENDING = {};
|
|
static STATUS_RUNNING = {};
|
|
static STATUS_DONE = {};
|
|
constructor () {
|
|
this.status_ = this.constructor.STATUS_PENDING;
|
|
this.donePromise = new Promise((resolve, reject) => {
|
|
this.doneResolve = resolve;
|
|
this.doneReject = reject;
|
|
});
|
|
}
|
|
get status () {
|
|
return this.status_;
|
|
}
|
|
set status (status) {
|
|
this.status_ = status;
|
|
if ( status === this.constructor.STATUS_DONE ) {
|
|
this.doneResolve();
|
|
}
|
|
}
|
|
awaitDone () {
|
|
return this.donePromise;
|
|
}
|
|
onComplete (fn) {
|
|
this.donePromise.then(fn);
|
|
}
|
|
}
|