import { createChannel } from "https://deno.land/x/effection@3.0.0-beta.3/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
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.subscribe();
let subscription2 = yield* channel.subscribe();
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' }
});