import { AsyncCTX, AsyncContext, ContextToken, Context } from '@lzptec/ctx';
const token = new ContextToken<number>();
const tokenWithDefault = new ContextToken<number>(() => 123);
const context = new AsyncContext();
const printContextValue = () => {
console.log(context.get(token));
};
const run = () => {
await context.run(() => {
printContextValue(); // Print undefined
// Async Context
context.set(token, 987);
printContextValue(); // Print token value 987
});
// Outside Async Context
printContextValue(); // throw a ReferenceError
};
run();
-
Notifications
You must be signed in to change notification settings - Fork 0
Dead Simple Context manager.
License
LzpTec/ctx
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Dead Simple Context manager.
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published