No matching definitions.

tur/session

stdlib/session.tur

standard session-type protocol patterns for typed channels.

Since: Phase B1

defn linear

echo-server-loop

(echo-server-loop [^linear ch :(Session (Rec self (Branch (Recv int (Send int self)) Close)))] :nil)

serve the echo protocol until the client closes.

chserver-side channel with protocol
Session[Rec self (Branch (Recv int (Send int self)) Close)]

nil -- the function returns after the client sends Close

(spawn (fn [] (echo-server-loop server-end)))

Since: SS4

defn linear

echo-client-call

(echo-client-call [^linear ch :(Session (Rec self (Choose (Send int (Recv int self)) Close))) val :int] :[(int)

send one integer and receive the echo.

chclient-side channel with protocol
Session[Rec self (Choose (Send int (Recv int self)) Close)]
valinteger to send and have echoed back

A pair [echoed-value, updated-channel] where updated-channel still has the recursive EchoClientProto so more calls can be made.

(let [[r ch] (echo-client-call ch 42)]
    (println r))   ; => 42

Since: SS4

defn linear

rpc-call

(rpc-call [^linear ch :(Session (Send int (Recv int Close))) req :int] :int)

perform a single RPC: send request, receive response, close.

chclient channel with protocol Session[Send int (Recv int Close)]
reqinteger request value to send to the server

The integer response received from the server. The channel is fully consumed (closed) by this call.

(let [resp (rpc-call ch 21)]
    (println resp))   ; => 42 (if server doubles the value)

Since: SS4

defn linear

pubsub-recv-loop

(pubsub-recv-loop [^linear ch :(Session (Recv int (Rec self (Branch (Recv int self) Close)))) handler :(-> int nil)] :nil)

receive messages from a topic until it closes.

chsubscriber channel with protocol
Session[Recv int (Rec self (Branch (Recv int self) Close))]
handlerfunction called with each received integer message

nil -- returns after the topic sends the Close branch

(pubsub-recv-loop sub-ch (fn [msg] (println msg)))

Since: SS4

defn linear

pubsub-recv-loop-inner

(pubsub-recv-loop-inner [^linear ch :(Session (Rec self (Branch (Recv int self) Close))) handler :(-> int nil)] :nil)

inner recursive loop after initial recv.