rx-tx-async-channel
1 Description
2 Synopsis
3 API
rx-tx-async-channel+  +
rx-tx-async-channel.to-child
rx-tx-async-channel.to-parent
async-channel-most-recent-message
8.12

rx-tx-async-channel🔗ℹ

David K. Storrs

 (require rx-tx-async-channel) package: rx-tx-async-channel

1 Description🔗ℹ

Defines a struct containing two async-channels in order to make bi-directional communication simple. Relies on the struct-plus-plus module.

The two fields are called to-child and to-parent with the intent that the struct is created in one thread (the parent) and given to another thread (the child), and the fields specify who is expected to receive the messages–the parent thread receives messages that are put on to-parent and vice versa.

2 Synopsis🔗ℹ

> (require struct-plus-plus racket/async-channel rx-tx-async-channel)
; The rx-tx-async-channel struct was defined via struct-plus-plus, meaning
; it has a keyword constructor and dotted accessors in addition to the normal
; `struct`-generated versions.
; 
; Both #:to-child and #:to-parent are optional, so the following are essentially equivalent:
> (define x1 (rx-tx-async-channel++ #:to-child (make-async-channel) #:to-parent (make-async-channel)))
> (define ch (rx-tx-async-channel++))
; Obviously, you can also specify one argument and let the other default.
> (rx-tx-async-channel? ch)

#t

> (async-channel? (rx-tx-async-channel.to-child ch))

#t

> (async-channel? (rx-tx-async-channel.to-parent ch))

#t

> (define parent (rx-tx-async-channel.to-parent ch))
> (define child (rx-tx-async-channel.to-child ch))
> (async-channel-put parent 1)
> (async-channel-put parent 2)
> (async-channel-put parent 3)
> (async-channel-put child  'a)
> (async-channel-put child  'b)
> (async-channel-put child  'c)
> (async-channel-get parent)

1

> (async-channel-get child)

'a

> (async-channel-most-recent-message parent)

3

> (async-channel-most-recent-message child)

'c

3 API🔗ℹ

procedure

(rx-tx-async-channel++ #:to-child async-channel? 
  #:to-parent async-channel) 
  rx-tx-async-channel?
  async-channel? : (make-async-channel)
  async-channel : (make-async-channel)
Keyword constructor.

procedure

(rx-tx-async-channel.to-child rtc)  async-channel?

  rtc : rx-tx-async-channel?
Dotted accessor created by struct-plus-plus.

procedure

(rx-tx-async-channel.to-parent rtc)  async-channel?

  rtc : rx-tx-async-channel?
Dotted accessor created by struct-plus-plus.

procedure

(async-channel-most-recent-message ch)  any/c

  ch : async-channel?
Read from the async channel. If no messages are available, return #f. Otherwise, read repeatedly until no messages remain, then return the last message.