src/lsp/transport/service.bend
bolt@1.17.0.0 · 18 lines · 0 definitions
1# transport: an effect service: one message body in, one out. H is the
2# implementation's handle state; it is affine, so every call hands it back.
3import Base
4
5# effect service over a handle H: receive a body, send a body, each handing the
6# handle back
7type Transport<-H: Type> is Type: # noqa: L001 effect record
8 Transport{recv: H -> IO(H & Maybe<&2, String>), send: H -> String -> IO(H)}
9
10# the next message's body; None when the peer is gone
11def recv(-H: Type, tt: Transport<H>, hh: H) -> IO(H & Maybe<&2, String>): # noqa: L001 effect accessor
12 Transport{r, s} = tt
13 r(hh)
14
15# a body, through a transport
16def send(-H: Type, tt: Transport<H>, hh: H, body: String) -> IO(H): # noqa: L001 effect accessor
17 Transport{r, s} = tt
18 s(hh, body)