schan
stdlib/schan.tur
session-typed channel wrappers over a linear opaque handle.
Since: S1
defopaque
SSend
(SSend [T R] :int))
protocol step: send a value of type T, then continue as R.
defopaque
SRecv
(SRecv [T R] :int))
protocol step: receive a value of type T, then continue as R.
defopaque
SClose
(SClose)
protocol terminus: the channel is closed.
defopaque
linear
SChan
(SChan [P] :ptr<void>)
a linear channel handle carrying a protocol phantom P.
Since: S1
defn
schan-new
(schan-new [P])
open a session-typed channel running protocol P.
Parameters
| cap | ring-buffer capacity (>= 1) |
Returns
A fresh SChan<P>. The protocol P is fixed by the call site's expected type (or an ascription).
Example
(:: (schan-new 4) (SChan (SSend int SClose))) ; => SChan<SSend int SClose>
Since: S1
defn
schan-send
(schan-send [T R])
send a T over a channel whose protocol begins with SSend T R.
Parameters
| c | channel at protocol SSend<T R> (consumed) | |
| v | the value to send |
Returns
The same channel, advanced to protocol R.
Example
(let [c2 (schan-send c 42)] ...) ; c : SChan<SSend int R> => c2 : SChan<R>
Since: S1
defn
schan-recv
(schan-recv [T R])
defn
schan-close
(schan-close [c : (SChan SClose)] :)
close a channel whose protocol has reached SClose.
Parameters
| c | channel at protocol SClose (consumed) |
Returns
nil. The underlying channel is freed.
Example
(schan-close c) ; c : SChan<SClose>
Since: S1
Internal definitions
schan-recv-value-- receive a T from a channel whose protocol begins with SRecv T R.schan-advance-recv-- internal: retag the channel from SRecv T R to R.