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

x/effection/lib/mod.ts>createSignal

Structured concurrency and effects for JavaScript
Latest
function createSignal
Re-export
import { createSignal } from "https://deno.land/x/effection@4.0.0-alpha.1/lib/mod.ts";

Create a new Signal

Signal should be used when you need to send messages to a stream from outside of an operation. The most common case of this is to connect a plain, synchronous JavaScript callback to an operation.

Examples

Example 1

function* logClicks(button) {
  let clicks = createSignal<MouseEvent>();
  try {
    button.addEventListener("click", clicks.send);

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

Do not use a signal to send messages from within an operation as it could result in out-of-scope code being executed. In those cases, you should use a Channel.

Type Parameters

T
optional
TClose = never