On this page:
3.1 Multicast Asynchronous Channels

3 Concurrent

3.1 Multicast Asynchronous Channels

 (require grip/concurrent/multicast) package: grip

This provides an implementation of multicast channels, an extension of asynchronous channels that may have multiple recievers. Unlike asynchronous channels, multicast channels have distinct “server” and “receiver” objects, since multicast channels create a one-to-many relationship.

Ported from dynamically typed implementation by Alexis King.

The Multicast-Channelof parameterized by the type of the broadcast message being sent/received. e.g. (Multicast-Channelof String).

The Multicast-Receiverof type that is parameterized by the broadcast message type being received/sent. e.g. (Multicast-Receiverof String).

Creates and returns a new Multicast-Channelof instance. A created instance of Multicast-Channelof weakly holds instances of created Multicast-Receiverof instances allowing for automatic gc’ing and cleanup.


(make-multicast-receiver mc)  (Multicast-Receiverof a)

  mc : (Multicast-Channelof a)
Creates a receiver asynchronous channel that receives messages from mc. The returned value is a type alias for a standard Async-Channelof from typed/racket/async-channel, but it does not support async-channel-put. Attempting to write to a receiver channel will raise an exception.

The created Multicast-Receiverof instance is weakly held by the Multicast-Channelof instance creator. When the client caller to this method lets the returned Multicast-Receiverof instance go out of scope it will be gc’d and de-registered from the Multicast-Channelof instance. Explicit closing of a Multicast-Receiverof instance is not required.


(multicast-channel-put mc v)  Void

  mc : (Multicast-Channelof a)
  v : a
Broadcasts v of to all receivers listening to mc.