Files
smartcontext/ts/classes.asynccontext.ts

19 lines
533 B
TypeScript
Raw Permalink Normal View History

import * as plugins from './plugins.js';
import { AsyncStore } from './classes.asyncstore.js';
export class AsyncContext {
2026-02-15 20:09:47 +00:00
private _context = new plugins.AsyncLocalStorage<AsyncStore>();
private _store = new AsyncStore();
get store() {
2026-02-15 20:09:47 +00:00
return this._context.getStore() || this._store;
}
set store(value: AsyncStore) {
this._store = value;
}
public async runScoped(functionArg: () => Promise<void>) {
await this._context.run(new AsyncStore(this.store), async () => {
await functionArg()
});
}
}