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

x/effection/lib/instructions.ts>suspend

Structured concurrency and effects for JavaScript
Latest
function suspend
import { suspend } from "https://deno.land/x/effection@3.0.3/lib/instructions.ts";

Indefinitely pause execution of the current operation. It is typically used in conjunction with an action to mark the boundary between setup and teardown.

function onEvent(listener, name) {
  return action(function* (resolve) {
    try {
      listener.addEventListener(name, resolve);
      yield* suspend();
    } finally {
      listener.removeEventListener(name, resolve);
    }
  });
}

An operation will remain suspended until its enclosing scope is destroyed, at which point it proceeds as though return had been called from the point of suspension. Once an operation suspends once, further suspend operations are ignored.

Returns

Operation<void>

an operation that suspends the current operation