11.2.4 Buffered Asynchronous Channels
(require racket/async-channel) | package: base |
11.2.4.1 Creating and Using Asynchronous Channels
See also Thread Mailboxes.
An asynchronous channel is like a channel, but it buffers values so that a send operation does not wait on a receive operation.
In addition to its use with procedures that are specific to asynchronous channels, an asynchronous channel can be used as a synchronizable event (see Events). An asynchronous channel is ready for synchronization when async-channel-get would not block; the asynchronous channel’s synchronization result is the same as the async-channel-get result.
procedure
(async-channel? v) → boolean?
v : any/c
procedure
(make-async-channel [limit]) → async-channel?
limit : (or/c exact-positive-integer? #f) = #f
procedure
(async-channel-get ach) → any/c
ach : async-channel?
procedure
(async-channel-try-get ach) → any/c
ach : async-channel?
procedure
(async-channel-put ach v) → void?
ach : async-channel? v : any/c
procedure
(async-channel-put-evt ach v) → evt?
ach : async-channel? v : any/c
Examples: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
11.2.4.2 Contracts and Impersonators on Asynchronous Channels
procedure
(async-channel/c c) → contract?
c : contract?
If the c argument is a flat contract or a chaperone contract, then the result will be a chaperone contract. Otherwise, the result will be an impersonator contract.
When an async-channel/c contract is applied to an asynchronous channel, the result is not eq? to the input. The result will be either a chaperone or impersonator of the input depending on the type of contract.
procedure
(impersonate-async-channel channel get-proc put-proc prop prop-val ... ...) → (and/c async-channel? impersonator?) channel : async-channel? get-proc : (any/c . -> . any/c) put-proc : (any/c . -> . any/c) prop : impersonator-property? prop-val : any
The get-proc must accept the value that async-channel-get produces on channel; it must produce a replacement value, which is the result of the get operation on the impersonator.
The put-proc must accept the value passed to async-channel-put called on channel; it must produce a replacement value, which is the value passed to the put procedure called on the original channel.
The get-proc and put-proc procedures are called for all operations that get or put values from the channel, not just async-channel-get and async-channel-put.
Pairs of prop and prop-val (the number of arguments to impersonate-async-channel must be odd) add impersonator properties or override impersonator property values of channel.
procedure
(chaperone-async-channel channel get-proc put-proc prop prop-val ... ...) → (and/c async-channel? chaperone?) channel : async-channel? get-proc : (any/c . -> . any/c) put-proc : (any/c . -> . any/c) prop : impersonator-property? prop-val : any