menu

ContextVar

import { ContextVar } from "destack:context";

One dynamically scoped execution value.

language/library/src/context/variable.ds:7:31
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: string

Diagnostic name.

defaultValue: T

Value outside an overriding scope.

constructor(name: string, defaultValue: T)

Create one context variable.

get(): T

Return the current value.

run<R>(value: T, body: () => R): R

Run body with value bound to this variable.