1
Atdalīts 0

disable async hook when possible

This commit is contained in:
Conduitry 2019-06-08 08:31:02 -04:00
vecāks 96bbb8c28b
revīzija 8893733364
2 mainīti faili ar 18 papildinājumiem un 3 dzēšanām

Parādīt failu

@ -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

Parādīt failu

@ -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);