Skip to content
Trigora
Start building →

Your first Program

A Program is one durable function. This one takes no parameter.

import { effect, waitForEvent } from "@trigora/sdk";
export default async function approval() {
const result = await effect("generate", () => 42);
const review = await waitForEvent("approved");
return { result, review };
}

Put it on the programs glob in trigora.toml. The export name is the id you pass to trigora start.

Terminal window
trigora start approval

What happens:

  1. Trigora starts an Execution of approval.
  2. generate runs. Its outcome is committed.
  3. The Execution waits on approved. Compute is released.
  4. trigora send <execution-id> approved delivers the event.
  5. The Execution resumes after the wait and returns both values.

If the process dies during the wait, recovery loads the committed continuation and stays at the wait. It does not run generate again.

Python and Rust use the same structure with language-specific names. The Python Program id is the file stem. A Rust Program id is the source file stem, or the Cargo package name for lib.rs and main.rs.

from trigora import effect, program, wait_for_event
@program
async def approval():
result = await effect("generate", lambda: 42)
review = await wait_for_event("approved")
return {"result": result, "review": review}
use trigora::{effect, wait_for_event};
pub struct Approval {
pub result: f64,
pub review: bool,
}
pub async fn main() -> Result<Approval, String> {
let amount: f64 = 42.0;
let result = effect("generate", move || amount).await?;
let review: bool = wait_for_event("approved").await?;
Ok(Approval { result, review })
}

Calling the function yourself fails. trigora start targets trigora dev by default. Add --remote to start on Trigora Cloud. A language client uses Cloud when a token is set, and the local runtime otherwise.

Start input is an ordered argument list:

export default async function research(topic, limit = 10) {
return { topic, limit };
}
Terminal window
trigora start research --input '["tcc"]'

Python is one @program async function. Rust is one pub async fn main. See Programs. Structured concurrency is a separate page: Structured concurrency.