import type { Operation, Stream } from "./types.js"; /** * A broadcast channel that multiple consumers can subscribe to the * via the same {@link Stream}, and messages sent to the channel are * received by all consumers. The channel is not buffered, so if there * are no consumers, the message is dropped. * @since 3.0 */ export interface Channel extends Stream { /** * Send a message to all subscribers of this {@link Channel} */ send(message: T): Operation; /** * End every subscription to this {@link Channel} */ close(value: TClose): Operation; } /** * Create a new {@link Channel}. Use channels to communicate between operations. * In order to dispatch messages from outside an operation such as from a * callback, use {@link Signal}. * * See [the guide on Streams and * Subscriptions](https://frontside.com/effection/docs/guides/collections) * for more details. * * @example * * ``` javascript * 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' } * }); * ``` * @since 3.0 */ export declare function createChannel(): Channel;