Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/channel/custom/index.ts

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
import * as rimbu from "https://deno.land/x/rimbu@1.2.0/channel/custom/index.ts";

Namespaces

A RemoteChannel is a channel that communicates through a message port of the RemoteChannel.SimpleMessagePort type. This makes it usable for cross-environment channel communication, e.g. cross threads or even cross network. Like CrossChannel, RemoteChannel does not receive its own sent messages, but requires another end to communicate.

RemoteObject offers a convenient way to retrieve data and invoke methods across a RemoteChannel. It involves setting up a remote object server that takes a given TypeScript object and allows a remote object client to perform remote calls to this object and getting the results.

Classes

Error indicating that an attempt to read from a Channel failed because a read is already ongoing.

Error indicating that an attempt to send to a Channel failed because a send is already ongoing.

Error indicating that a Channel is closed when performing an operation.

The abstract base class/type for Channel Errors.

Error indicating that a Channel is exhausted when performing an operation.

Error indicating that a Channel handshake failed.

Error indicating that a Channel message has an incorrect type.

Error indicating that a Channel operation was aborted.

Error indicating that a timeout has occured during a Channel operation.

The abstract base class/type for RemoteObject Errors.

Error indicating that a remote object property did not exist,

Error indicating that a remote function call was not actually a function,

Error indicating that a path part is not of the expected tyoe,

Error indicating that an attempt was made to perform an unsafe operation.

Error indicating an attempt was made to access a non-string property,

The abstract base class/type for RpcProxy Errors.

Error indicating a request was made to release more weight than reserved.

Error indicating that the semaphore does not have sufficient capacity.

Error indicating that an invalid configuration was provided,

The abstract base class/type for Semaphore Errors.

Functions

Attaches the given function to the given abort signal if the signal is not undefined or aborted. Returns a cleanup function that will remove the function from the abort signal or undefined in case one of the conditions mentioned earlier prevents the function from being attached.

Returns true if the given object is an instance of a ChannelError.

Returns a promise that will resolve deferred (immediately but not in the current loop).

Returns a random integer between the given min and max (both inclusive).

Returns a four-digit random number that can serve as a sequence number.

Returns true if the given object is an instance of a RemoteObjectError.

Returns true if the given object is an instance of a RpcProxyError.

Returns true if the given object is an instance of a SemaphoreError.

Returns a promise that is resolved after the given amount of milliseconds.

Performs the given action function after the given timeoutMs milliseconds, unless the returns cancel function is called before the timer expires.

Interfaces

A Rimbu Channel offers various ways to synchronize communication between asynchronous processes. These processes can send and receive messages in a blocking way. Channel messages are of type T, and channels can be buffered or unbuffered. A buffered channel can queue a given amount of messages before blocking the sender.

The configuration options for creating a Channel.

Defines the static Channel API.

A read-only Channel that can perform blocking reads. This means that a receive call will block until a message is available.

A write-only Channel that can perform blocking writes. This means that a send call will block until the channel has capacity to send a message.

Utility that can be used to clean up resources after usage.

A CrossChannel is a channel of which the send and receive modules are not internally connected. This means that the send and receive message types can also differ. A normal Channel can receive its own message, but a CrossChannel cannot, and so they are usually created in pairs to perform bidirectional communication with some other entity.

Configuration options for creating a CrossChannel

Defines the static CrossChannel API.

A Mutex is used to restrict access to a shared resource in a concurrent environment. The Mutex can be used to acquire a lock for the resource, preventing others using the Mutext from accessing the resource. When finished using the resource, the lock can be released, allowing other waiting processes to acquire a lock.

Defines the static Mutex API.

Defines the static RemoteChannel API.

Interface defining the cross-channel configuration for a RemoteChannel.

Interface defining the read configuration for a RemoteChannel.

Interface used to perform low-level message communication between processes. Compatible with browser, Node, and Worker contexts.

Interface defining the write configuration for a RemoteChannel.

A RemoteChannelClient allows creating channels to communicate with a RemoteChannelServer. The server should be configured to listen to channels with the channel ids provided to the channel creation functions in the client.

Interface defining the confirgartion options for a RemoteChannelClient

Defines the static RemoteChannelClient API.

Interface defining the configuration options for creating a remote Channel.Cross channel

Interface defining the configuration options for creating a remote Channel.Read channel

Interface defining the configuration options for creating a remote Channel.Write channel

A RemoteChannel server communicates with a RemoteChannel client through the given message port, and allows clients to easily create new channels to communicate with processes in the server context. The server needs to set up handlers to deal with the created channels.

Defines the static RemoteChannelServer API.

Interface defining a remote call structure.

Defines the static RemoteObject API.

A remote procedure call proxy that can be used to perform methods on a remote object as though it is accessible locally.

Defines the static RpcProxy API.

A Semaphore is a generalized version of a Mutex, allowing boundaries on the amount of concurrent processes that can have simultaneous access to a shared resource. The semaphore is weighted, meaning that the semaphore has a maximum size/capacity available for the shared resources. When acquiring the resource, a weight can be provided allowing more intensive tasks to acquire a larger share of the shared resource, preventing too many other tasks from also acquiring the resource.

Defines the static Semaphore API.

A WaitGroup is a way to perform fork-join logic in an asynchronous context. It allows a process to create an arbitrary amount of sub-processes, and wait for all of them to finish before continuing.

Defines the static WaitGroup API.

Type Aliases

The Channel Error type.

Utility type to extract the message type from a Channel.

A pair of CrossChannels in which the send module of the first is connected to the receive of the second, and the send module of the second is connected to the receive module of the first.

Type defining the RemoteObject client channel type.

The RemoteObject Error type.

Type defining a remote call response structure

Type defining the RemoteObject server channel type.

The RpcProxy error type

An RPC call path, consisting of an array of path parts

A part of an RPC call path, which can be either:

  • a string indicating an object property/method
  • an array of data indicating a function call with the array as arguments

Utility type to transform an object/API with potentially asynchronous calls into a synchronous one. This is used to allow RPC calls to act as though they are synchronous, but have only the resulting return type be asynchronous.

The semaphore error type.