Effects
Signature
Section titled “Signature”function effect<T>(name: string, run: () => T | Promise<T>): Promise<T>def effect(name: str, fn: Callable[[], T]) -> TParameters
Section titled “Parameters”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.
Return value
Section titled “Return value”The resolved value of run. On recovery after that outcome is committed, the same value is returned and run is not executed again.
Durable semantics
Section titled “Durable semantics”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.
Failure
Section titled “Failure”- An empty name throws before the effect runs.
- If
runthrows and that failure is not a committed success, the Execution can fail. - Calling
effectoutside an Execution throws and tells you to start the Program with the client whiletrigora devis running, or through Cloud after deploy.
Example
Section titled “Example”const result = await effect("generate", async () => { return 42;});