mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-19 12:37:05 +00:00
* style(puterfs): update adherence to linter rules * fix(puterfs): await queue items for fsentry actions This will ensure some operations always function as expected in a sequence, although it may incur some performance costs.
32 lines
757 B
JavaScript
32 lines
757 B
JavaScript
import { TeePromise } from 'teepromise';
|
|
|
|
export default class BaseOperation {
|
|
static STATUS_PENDING = {};
|
|
static STATUS_RUNNING = {};
|
|
static STATUS_DONE = {};
|
|
|
|
/** @type {PromiseLike<void> & { resolve: () => void }} */
|
|
#donePromise;
|
|
|
|
constructor () {
|
|
this.status_ = this.constructor.STATUS_PENDING;
|
|
this.#donePromise = new TeePromise();
|
|
}
|
|
get status () {
|
|
return this.status_;
|
|
}
|
|
set status (status) {
|
|
this.status_ = status;
|
|
if ( status === this.constructor.STATUS_DONE ) {
|
|
this.#donePromise.resolve();
|
|
}
|
|
}
|
|
async awaitDone () {
|
|
await this.#donePromise;
|
|
}
|
|
async onComplete (fn) {
|
|
await this.#donePromise;
|
|
fn();
|
|
}
|
|
}
|