Skip to content
Trigora
Start building →

Effects

function effect<T>(name: string, run: () => T | Promise<T>): Promise<T>
def effect(name: str, fn: Callable[[], T]) -> T
  • name — non-empty string. In a Program it must be a string literal. This is the effect identity.
  • run / fn — the work. It runs at the boundary. It is not itself a second Program.

The resolved value of run. On recovery after that outcome is committed, the same value is returned and run is not executed again.

The effect is one durable operation. The key is the name at that position in the Program. A committed outcome is reused. If the process dies before the outcome is committed, the effect may run again. Trigora does not make the external system exactly-once. See Effect identity and Production considerations.

  • An empty name throws before the effect runs.
  • If run throws and that failure is not a committed success, the Execution can fail.
  • Calling effect outside an Execution throws and tells you to start the Program with the client while trigora dev is running, or through Cloud after deploy.
const result = await effect("generate", async () => {
return 42;
});