RELAYCall

wait_for

View as MarkdownOpen in Claude

Wait for a specific event type on this call, optionally filtered by a predicate function. This is a one-shot listener — it resolves on the first matching event and then removes itself.

Parameters

event_type
strRequired

The event type string to wait for.

predicate
Optional[Callable[[RelayEvent], bool]]

Optional filter function. If provided, the wait only resolves when the predicate returns True for a received event.

timeout
Optional[float]

Maximum seconds to wait. Raises asyncio.TimeoutError if exceeded. None waits indefinitely.

Returns

RelayEvent — The first event matching the type and optional predicate.

Example

1from signalwire.relay import RelayClient
2
3client = RelayClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7 contexts=["default"],
8)
9
10@client.on_call
11async def handle_call(call):
12 await call.answer()
13
14 # Wait for a specific play event
15 action = await call.play([{"type": "tts", "text": "Hello!"}])
16 event = await call.wait_for(
17 "calling.call.play",
18 predicate=lambda e: e.params.get("state") == "finished",
19 timeout=30,
20 )
21 print(f"Play finished: {event.params}")
22
23client.run()