Newer version available
You’re viewing the API reference for version 3.0.3, but the latest version is 3.1.0. The latest version include may important updates and fixes.
View Latest Versionfunction createChannel
thefrontside/effectionfunction createChannel<T, TClose = void>(): Channel<T, TClose>
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
TClose = void
Return Type
Channel<T, TClose>