smartcontext/ts/logcontext.classes.asynccontext.ts

20 lines
608 B
TypeScript
Raw Normal View History

import * as plugins from './logcontext.plugins.js';
import { AsyncStore } from './logcontext.classes.asyncstore.js';
export class AsyncContext {
private _context = new plugins.simpleAsyncContext.AsyncContext.Variable<AsyncStore>();
private _store = new AsyncStore();
get store() {
return this._context.get() || this._store;
}
set store(value: AsyncStore) {
this._store = value;
}
public async runScoped(functionArg: () => Promise<void>) {
const childStore = new AsyncStore(this.store);
await this._context.run(childStore, async () => {
await functionArg()
});
}
}