Skip to main content
Module

x/effection/mod.ts>Operation

Structured concurrency and effects for JavaScript
Go to Latest
interface Operation
Re-export
import { type Operation } from "https://deno.land/x/effection@3.0.0-beta.3/mod.ts";

An Operation in Effection describes an abstract computation. An operation does not do anything on its own. Rather, it only describes the steps it will take when it runs.

In the Effection world, Operation occupies the same position as Promise does the world of async/await.

An operation can be created with a generator function that only does yield* to other operations:

Examples

Example 1

import { sleep } from "effection";

function* slow5(seconds) {
  yield* sleep(seconds * 1000);
  return 5;
}

Operations can also be created using Symbol.iterator. The following operation is the same as above:

Example 2

import { sleep } from "effection";

const slow5 = (seconds) => ({
  *[Symbol.iterator]() {
    yield* sleep(seconds * 1000);
    return 5;
  }
})

See Operations guide for more information.

Methods

[[Symbol.iterator]](): Iterator<Instruction, T, any>