Effection Logo

interface Scope

thefrontside/effection

interface Scope

A programatic API to interact with an Effection scope from outside of an https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation.

Most often this is used to integrate external APIs with Effection by capturing a Scope from a running operation with https://effection-www-pggsafb7y58a.deno.dev/api/v4/useScope, and then using it to call back into itself from a callback.

The following example calls into Effection to implement a proxy around a google search by using express.js.

Examples

Example 1

import { main, useScope, suspend } from "effection";
import { express } from "express";

await main(function*() {
  let scope = yield* useScope();
  express().get("/", (req, resp) => {
    return scope.run(function*() {
      let signal = yield* useAbortSignal();
      let response = yield* fetch(`https://google.com?q=${req.params.q}`, { signal });
      resp.send(yield* response.text());
    });
  });
  yield* suspend();
});

Methods

run<T>(operation: () => https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation&lt;T>): https://effection-www-pggsafb7y58a.deno.dev/api/v4/Task&lt;T>

Run an https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation within Scope.

This is used to create concurrent tasks from outside of a running operation. To create concurrent tasks from within an already running operation, use https://effection-www-pggsafb7y58a.deno.dev/api/v4/Scope

spawn<T>(operation: () => https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation&lt;T>): https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation&lt;https://effection-www-pggsafb7y58a.deno.dev/api/v4/Task&lt;T>>

Spawn an https://effection-www-pggsafb7y58a.deno.dev/api/v4/Operation within Scope.

This is used to create concurrent tasks from within a running operation. To create concurrent from outside of Effection, use https://effection-www-pggsafb7y58a.deno.dev/api/v4/Scope

get<T>(context: https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context&lt;T>): T | undefined

Get a https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context value from outside of an operation.

set<T>(context: https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context&lt;T>, value: T): T

Set the value of a https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context from outside of an operation

expect<T>(context: https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context&lt;T>): T

Get a https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context value from outside of an operation, and throw a MissingContextError if this context is not specified for this scope.

delete<T>(context: https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context&lt;T>): boolean

Remove a https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context value from this scope.

hasOwn<T>(context: https://effection-www-pggsafb7y58a.deno.dev/api/v4/Context&lt;T>): boolean

Check if scope has its own unique value for context.