sync tested.
This commit is contained in:
@@ -1,8 +1,46 @@
|
||||
# uni-channel
|
||||
|
||||
`uni-channel` provides a uniform facade over `async-channel`, `place-channel` and `port-channel`.
|
||||
`uni-channel` provides one simple wrapper over `async-channel`, `place-channel`
|
||||
and `port-channel`.
|
||||
|
||||
The package does not vendor `port-channel`; install `port-channel` from the Racket package index first.
|
||||
```racket
|
||||
(make-uni-channel channel)
|
||||
```
|
||||
|
||||
The constructor detects the concrete channel kind and returns a `uni-channel?`.
|
||||
No helper constructors are part of the public API; create the underlying channel
|
||||
with the normal Racket or `port-channel` constructor and then wrap it.
|
||||
|
||||
A wrapped channel that can receive is itself synchronizable. `(sync ch)` returns
|
||||
the value received from the underlying channel. For an output-only endpoint, such
|
||||
as an output `port-channel`, the receive event is `never-evt` because no value can
|
||||
be received from that endpoint.
|
||||
|
||||
|
||||
```racket
|
||||
(require racket/async-channel
|
||||
uni-channel)
|
||||
|
||||
(define ch (make-uni-channel (make-async-channel)))
|
||||
(uni-channel-send ch 'hello)
|
||||
(uni-channel-recv ch)
|
||||
```
|
||||
|
||||
For `port-channel`, wrap the input and output endpoints separately:
|
||||
|
||||
```racket
|
||||
(require port-channel
|
||||
uni-channel)
|
||||
|
||||
(define-values (in out) (make-pipe))
|
||||
(define reader (make-uni-channel (make-port-channel in)))
|
||||
(define writer (make-uni-channel (make-port-channel out)))
|
||||
|
||||
(uni-channel-send writer '(hello 1 2 3))
|
||||
(uni-channel-recv reader)
|
||||
```
|
||||
|
||||
Install and test:
|
||||
|
||||
```sh
|
||||
raco pkg install --auto port-channel
|
||||
@@ -10,19 +48,3 @@ raco pkg install --auto ./uni-channel
|
||||
raco test -x -p uni-channel
|
||||
raco setup --pkgs uni-channel
|
||||
```
|
||||
|
||||
Main API:
|
||||
|
||||
```racket
|
||||
make-uni-channel
|
||||
make-uni-async-channel
|
||||
make-uni-async-channel-pair
|
||||
make-uni-place-channel
|
||||
make-uni-place-channel-pair
|
||||
make-uni-port-channel
|
||||
uni-channel-put
|
||||
uni-channel-get
|
||||
uni-channel-send
|
||||
uni-channel-recv
|
||||
uni-channel-close
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user