smartcls/ts/index.ts
2024-06-06 18:26:11 +02:00

23 lines
545 B
TypeScript

import * as plugins from './smartcls.plugins.js';
export class SmartCls {
private asyncLocalStorage = new plugins.AsyncLocalStorage();
public run(runFunc: () => any) {
this.asyncLocalStorage.run({}, runFunc);
}
public set(keyArg: string, valueArg: any) {
const store: any = this.asyncLocalStorage.getStore();
store[keyArg] = valueArg;
}
public get(keyArg: string) {
const store: any = this.asyncLocalStorage.getStore();
if (store) {
return store[keyArg];
} else {
return undefined;
}
}
}