def stdio.act

ezmcp@0.1.0.0 · src/io.bend:263

import ezmcp@0.1.0.0/src/io.bend as Io
import Base
import emerging-ezjson@1.2.0.0/src/value.bend as Value
import ezmcp@0.1.0.0/src/rpc.bend as Rpc
import ezmcp@0.1.0.0/src/server.bend as Server
import ezmcp@0.1.0.0/src/line.bend as Line

263# act on one line's act, read by revision `rev`: write a reply as one line,
264# or run the tool and write its reply, or run a batch's acts and write the
265# array of their replies, or write nothing
266def stdio.act(
267  ~C: Data,
268  ~run: C -> String -> Value.Json -> IO(Rpc.Out),
269  +ctx: C,
270  +rev: String,
271  act: Server.Act
272) -> IO(Unit):
273  match act:
274    case Server.Quiet{}:
275      IO.pure(Unit, Unit{})
276    case Server.Send{reply}:
277      IO.write(Line.frame(reply))
278    case Server.Fault{reply}:
279      IO.write(Line.frame(reply))
280    case Server.Run{id, name, args}:
281      IO.bind(Rpc.Out, Unit, run(ctx, name, args),
282        out => IO.write(Line.frame(Server.ran(rev, id, out))))
283    case Server.Batch{acts}:
284      IO.bind(List<&2, Maybe<&2, Value.Json>>, Unit, act.all(C, run, ctx, rev, acts),
285        rs => stdio.batch(Server.batch.reply(rs)))

Uses (16)

Used by (1)