Skip to main content


Structured concurrency and effects for JavaScript
Go to Latest
interface Signal
implements Stream<T, TClose>
import { type Signal } from "";

Convert plain JavaScript function calls into a Stream that can be consumed within an operation. If no operation is subscribed to a signal's stream, then sending messages to it is a no-op.

Signals are particularly suited to be installed as event listeners.


Example 1

import { createSignal, each } from "effection";

export function* logClicks(function*(button) {
  let clicks = createSignal<MouseEvent>();

  button.addEventListener("click", clicks.send);

  try {
    for (let click of yield* each(clicks)) {
      console.log(`click:`, click);
  } finally {
    button.removeEventListener("click", clicks.send);


send(value: T): void

Send a value to all the consumers of this signal.

close(value: TClose): void

Send the final value of this signal to all its consumers.