system: add tests for fs usage route
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user