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

x/effection/lib/channel.ts>createChannel

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

Create a new Channel. Use channels to communicate between operations. In order to dispatch messages from outside an operation such as from a callback, use Signal.

See the guide on Streams and Subscriptions for more details.

Examples

Example 1

import { main, createChannel } from 'effection';

await main(function*() {
  let channel = createChannel();

  yield* channel.send('too early'); // the channel has no subscribers yet!

  let subscription1 = yield* channel;
  let subscription2 = yield* channel;

  yield* channel.send('hello');
  yield* channel.send('world');

  console.log(yield* subscription1.next()); //=> { done: false, value: 'hello' }
  console.log(yield* subscription1.next()); //=> { done: false, value: 'world' }
  console.log(yield* subscription2.next()); //=> { done: false, value: 'hello' }
  console.log(yield* subscription2.next()); //=> { done: false, value: 'world' }
});

Type Parameters

T
optional
TClose = void