system: add tests for fs usage route

This commit is contained in:
Girish Ramakrishnan
2025-07-17 01:16:24 +02:00
parent aa0c186c8c
commit 8bf8c278f0
9 changed files with 94 additions and 50 deletions

View File

@@ -6,12 +6,12 @@ const debug = require('debug')('box:asynctask'),
// this runs in-process
class AsyncTask extends EventEmitter {
#name;
name;
#abortController;
constructor(name) {
super();
this.#name = name;
this.name = name;
this.#abortController = new AbortController();
}
@@ -20,22 +20,19 @@ class AsyncTask extends EventEmitter {
}
async start() {
debug(`start: ${this.#name} started`);
debug(`start: ${this.name} started`);
const [error] = await safe(this._run(this.#abortController.signal)); // background
debug(`start: ${this.#name} done`, error);
this.done(error);
debug(`start: ${this.name} finished`);
this.emit('done', { errorMessage: error?.message || '' });
this.#abortController = null;
}
stop() {
debug(`stop: ${this.#name} stopped`);
if (this.#abortController === null) return; // already finished
debug(`stop: ${this.name} . sending abort signal`);
this.#abortController.abort();
}
done(error) {
debug(`done: ${this.#name} finished`);
this.emit('done', { errorMessage: error?.message || '' });
}
emitProgress(percent, message) {
this.emit('data', 'progress', { percent, message });
}