menu
ContextVar
import { ContextVar } from "destack:context";
One dynamically scoped execution value.
1export class ContextVar<T: Copy> {2 name: string;3 defaultValue: T;4 constructor(name: string, defaultValue: T);5 get(): T;6 run<R>(value: T, body: () => R): R;7}Members
name: stringDiagnostic name.
defaultValue: TValue outside an overriding scope.
constructor(name: string, defaultValue: T)Create one context variable.
get(): TReturn the current value.
run<R>(value: T, body: () => R): RRun
bodywithvaluebound to this variable.