replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
+5
-5
@@ -1,8 +1,8 @@
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import EventEmitter from 'node:events';
|
||||
import safe from 'safetydance';
|
||||
|
||||
const debug = debugModule('box:asynctask');
|
||||
const { log, trace } = logger('asynctask');
|
||||
|
||||
// this runs in-process
|
||||
class AsyncTask extends EventEmitter {
|
||||
@@ -20,16 +20,16 @@ class AsyncTask extends EventEmitter {
|
||||
}
|
||||
|
||||
async start() { // should not throw!
|
||||
debug(`start: ${this.name} started`);
|
||||
log(`start: ${this.name} started`);
|
||||
const [error] = await safe(this._run(this.#abortController.signal));
|
||||
debug(`start: ${this.name} finished`);
|
||||
log(`start: ${this.name} finished`);
|
||||
this.emit('done', { errorMessage: error?.message || '' });
|
||||
this.#abortController = null;
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.#abortController === null) return; // already finished
|
||||
debug(`stop: ${this.name} . sending abort signal`);
|
||||
log(`stop: ${this.name} . sending abort signal`);
|
||||
this.#abortController.abort();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user