function createChannel
thefrontside/effectionfunction createChannel<T, TClose = void>(): Channel<T, TClose>
Create a new https://effection-www-7a79x8qmc0zv.deno.dev/api/v4/Channel. Use channels to communicate between operations. In order to dispatch messages from outside an operation such as from a callback, use https://effection-www-7a79x8qmc0zv.deno.dev/api/v4/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
TClose = void
Return Type
https://effection-www-7a79x8qmc0zv.deno.dev/api/v4/Channel<T, TClose>