Skip to main content

Home > flowp > ChannelHub

ChannelHub class

compose multiple channels into one

Signature:

export declare class ChannelHub<T = unknown> implements PipeTarget<T> 

Implements: PipeTarget<T>

Constructors

ConstructorModifiersDescription
(constructor)(writers, readers)Constructs a new instance of the ChannelHub class

Methods

MethodModifiersDescription
broadcast(value)send a value to the hub, will be received by all readers
close()

close the hub and all readers/writers connected to it

no-op if already closed

disconnect(ch)

diconnect a channel from the hub, could be a reader or a writer

disconnected channel will NOT be closed automatically, they can still be used to send and receive messages

from(writers, readers)statica helper function, equivalant to ChannelHub.constructor
reader()

get a reader channel that can get messages from channel hub

use ChannelHub.disconnect() if you don't want to receive messages from the hub

writer()

get a writer channel that can send messages to channel hub

use ChannelHub.disconnect() if you don't want to send messages to the hub