disable async hook when possible
Este cometimento está contido em:
ascendente
96bbb8c28b
cometimento
8893733364
|
@ -86,6 +86,7 @@ export default class Defiler {
|
|||
|
||||
// execute everything, and return a promise that resolves when the first wave of processing is complete
|
||||
async exec(): Promise<void> {
|
||||
context.ref();
|
||||
if (this._status !== Status.Before) {
|
||||
throw new Error('defiler.exec: cannot call more than once');
|
||||
}
|
||||
|
@ -127,7 +128,11 @@ export default class Defiler {
|
|||
await done;
|
||||
this._status = Status.After;
|
||||
this._is_processing = false;
|
||||
this._enqueue();
|
||||
if (this._watchers.some(watcher => watcher.watch)) {
|
||||
this._enqueue();
|
||||
} else {
|
||||
context.unref();
|
||||
}
|
||||
}
|
||||
|
||||
// wait for a file to be available and retrieve it, marking dependencies as appropriate
|
||||
|
|
|
@ -2,10 +2,20 @@ import { createHook, executionAsyncId } from 'async_hooks';
|
|||
|
||||
const contexts = new Map<Number, any>();
|
||||
|
||||
createHook({
|
||||
const hook = createHook({
|
||||
init: (id, _, trigger) => contexts.set(id, contexts.get(trigger)),
|
||||
destroy: id => contexts.delete(id),
|
||||
}).enable();
|
||||
});
|
||||
|
||||
let refs = 0;
|
||||
|
||||
export const ref = (): void => {
|
||||
refs++ || hook.enable();
|
||||
};
|
||||
|
||||
export const unref = (): void => {
|
||||
--refs || hook.disable();
|
||||
};
|
||||
|
||||
export const create = (data: any): void => {
|
||||
contexts.set(executionAsyncId(), data);
|
||||
|
|
Carregando…
Criar uma nova questão referindo esta