Skip to main content


Structured concurrency and effects for JavaScript
Go to Latest
interface Operation
import { type Operation } from "";

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:


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.


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