smartcls/ts/index.ts

23 lines
545 B
TypeScript
Raw Normal View History

2024-06-06 16:26:11 +00:00
import * as plugins from './smartcls.plugins.js';
2017-10-12 09:19:54 +00:00
2020-07-20 07:39:47 +00:00
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();
2020-07-20 11:49:49 +00:00
if (store) {
return store[keyArg];
} else {
return undefined;
}
2020-07-20 07:39:47 +00:00
}
}