Effection Logo

function using

thefrontside/effection

function* using<T extends Disposable | AsyncDisposable>(value: T): Operation<T>

Bind a JavaScript disposable value to the current Effection scope.

The provided value is yielded immediately, then disposed when the owning scope exits (on return, error, or halt).

Examples

Example 1

import { run, using } from "effection";

class Connection {
  opened = true;
  [Symbol.dispose]() {
    this.opened = false;
  }
}

await run(function* () {
  let connection = yield* using(new Connection());
  connection.opened; // true while in scope
});

Type Parameters

T extends Disposable | AsyncDisposable

Parameters

value: T

Return Type

Operation<T>