Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/effection/lib/mod.ts>Context

Structured concurrency and effects for JavaScript
Latest
interface Context
Re-export
import { type Context } from "https://deno.land/x/effection@4.0.0-alpha.1/lib/mod.ts";

Context defines a value which is in effect for a given scope which is an (action, resource, call, or spawn).

Unless a context value is defined for a particular scope, it will inherit its value from its parent scope.

Properties

name: string

A unique identifier for this context.

optional
defaultValue: T

The value returned by this context when it is not present on a scop.e

Methods

get(): Operation<T | undefined>

Read the current value of this context if it exists.

set(value: T): Operation<T>

Set the value of a context on the current scope. It will not effect the value of its containing scope and will only be visible by this scope and its children.

expect(): Operation<T>

Read the current value of the context or fail if it does not exist

delete(): Operation<boolean>

Remove a context value from the current scope. This will only effect the current scope and not its parent value.

with<R>(value: T, operation: (value: T) => Operation<R>): Operation<R>

Evaluate an operation using value for the context. Once the operation is completed, the context will be reverted to its original value, or removed if it was not present originally.