Skip to content

Timeout & Waiting Strategy

TriggerFlow is event‑driven, so results may depend on external signals. Without timeouts, start() or get_result() can block indefinitely.

Why timeout matters

  • Event‑driven: flows often wait for emit() from outside
  • Async start: execution.async_start() is non‑blocking; results may arrive later
  • Operational stability: timeouts prevent hung requests and enable fallback

For linear flows where all chunks are guaranteed to finish, you can set timeout=0 (return immediately) or timeout=None (wait forever).

How timeout works

start() / get_result() wait on the internal result_ready event:

  • timeout=None: wait forever until end() or set_result()
  • timeout=0: return immediately (usually None)
  • timeout>0: return None and emit a timeout warning if not ready

Example: async trigger + timeout

python
from agently import TriggerFlow, TriggerFlowEventData

flow = TriggerFlow()

@flow.chunk
def approve(data: TriggerFlowEventData):
  return f"approved:{data.value}"

flow.when("User.Confirm").to(approve).end()

execution = flow.start_execution("start", wait_for_result=False)
print("before", execution.get_result(timeout=0.01))

execution.emit("User.Confirm", "ok")
print("after", execution.get_result(timeout=1))

Output (with a timeout warning once):

text
before None
after approved:ok

When timeout is not needed

  • A linear chain with guaranteed end()
  • You want to block until completion (timeout=None)