Files
puter/extensions/puterfs/fsentries/BaseOperation.js
T
Eric Dubé 2a027ed410 fix(puterfs): await queue items for fsentry action (#2616)
* 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.
2026-03-06 20:04:18 -05:00

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();
}
}