Skip to content
Playground(another site)

bynk.detach.in_agent_handler

Error A detach was used in an agent handler, which has no execution context to keep a detached effect alive.

detach stops waiting for an effect and hands it to the execution context, so something must keep the effect alive after the handler returns. A service handler has an execution context that does. An agent handler runs inside the agent's own object, with no such context, and its effects are awaited so that they finish with the handler. So detach is refused there, and in a closure there. Await the effect instead, with do or let _ <-, or move the detach to the service handler that calls the agent. A detach of a store operation is bynk.detach.store_op.

Example

on call bump() -> Effect[()] given Logger {
do Logger.info("bump").detach() // ✗ an agent handler cannot detach
do count.update((n) => n + 1)
}
on call bump() -> Effect[()] given Logger {
do Logger.info("bump") // ✓ awaited, so it finishes with the handler
do count.update((n) => n + 1)
}

In the Book

See also

  • The grammar rule it governs: method_call.
  • Every code in its category, Other, on the diagnostic index.
  • bynk explain bynk.detach.in_agent_handler shows the same from the installed toolchain, without a network.