def drain.message

bend-kit-camber@0.15.0.1 · camber.bend:106

import bend-kit-camber@0.15.0.1/camber.bend as Camber
import Base

106# Closing Base channels retains buffered messages. Drain them and answer stopped
107# callers, rather than stranding accepted commands behind the close command.
108def drain.message(~R: Type, ~P: Data, ~I: Data, ~E: Data, ~O: Data,
109  ~destroy: R -> IO(Unit), message: Message<R, P, I, E, O>
110) -> IO(Unit):
111  match message:
112    case Submit{principal, input, reply}:
113      do IO<Unit>:
114        sent : Result<&1, &1, Outcome<E, O>, Unit> <- Chan.send(Outcome<E, O>, reply, Stopped{})
115        return Unit{}
116    case Inspect{reply}:
117      Chan.close(Counts, reply)
118    case Shutdown{reply}:
119      do IO<Unit>:
120        sent : Result<&1, &1, CloseResult, Unit> <- Chan.send(CloseResult, reply, Closed{})
121        return Unit{}
122    case Returned{resource}:
123      destroy(resource)

Uses (11)

Used by (2)