@thi.ng/csp
Version:
Primitives & operators for Communicating Sequential Processes based on async/await and async iterables
64 lines • 2.1 kB
TypeScript
import type { IClosable, IWriteable } from "./api.js";
import { Channel } from "./channel.js";
/**
* Syntax sugar for {@link Mult} ctor. Creates a new `Mult` which allows
* multiple child subscriptions, each receiving the same values written to (or
* received by) the Mult itself, i.e. it acts as a channel splitter, supporting
* dynamic subscriptions and unsubscriptions.
*
* @remarks
* If `src` is a channel, it will be used as input. If given a string, a new
* channel with the given ID will be created (for receiving values).
*
* @param arg
*/
export declare const mult: <T>(arg?: string | Channel<T>) => Mult<T>;
export declare class Mult<T> implements IWriteable<T>, IClosable {
protected src: Channel<any>;
protected taps: Channel<any>[];
/**
* See {@link mult} for reference.
*
* @param arg
*/
constructor(arg?: string | Channel<T>);
writable(): boolean;
write(val: T): Promise<boolean>;
close(): void;
closed(): boolean;
/**
* Attaches (and possibly creates) a new subscription channel to receive any
* values received by the `Mult` itself. Returns it.
*
* @remarks
* The channel can later be detached again via {@link Mult.unsubscribe}.
*
* @param ch
*/
subscribe(ch?: Channel<T>): Channel<T>;
/**
* Attempts to remove given subscription channel. Returns true if
* successful. If `close` is true (default), the given channel will also be
* closed (only if unsubscription was successful).
*
* @remarks
* See {@link Mult.subscribe} for reverse op.
*
* @param ch
* @param close
*/
unsubscribe(ch: Channel<T>, close?: boolean): boolean;
/**
* Removes all child subscription channels and if `close` is true (default)
* also closes them.
*
* @remarks
* The `Mult` itself will remain active and will continue to accept new
* subscriptions.
*
* @param close
*/
unsubscribeAll(close?: boolean): void;
protected process(): Promise<void>;
}
//# sourceMappingURL=mult.d.ts.map