***

title: waitFor
slug: /reference/typescript/relay/call/wait-for
description: Wait for a specific event on a call.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[relayevent]: /docs/server-sdks/reference/typescript/relay/events

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**

<ParamField path="eventType" type="string" required={true} toc={true}>
  The event type string to wait for.
</ParamField>

<ParamField path="predicate" type="(event: RelayEvent) => boolean" toc={true}>
  Optional filter function. If provided, the wait only resolves when the
  predicate returns `true` for a received event.
</ParamField>

<ParamField path="timeout" type="number | undefined" toc={true}>
  Maximum milliseconds to wait. Throws an `Error` if exceeded. `undefined`
  waits indefinitely.
</ParamField>

## **Returns**

`Promise<`[`RelayEvent`][relayevent]`>` -- The first event matching the type and optional predicate.

## **Example**

```typescript {14}
import { RelayClient } from '@signalwire/sdk';

const client = new RelayClient({
  project: process.env.SIGNALWIRE_PROJECT_ID!,
  token: process.env.SIGNALWIRE_TOKEN!,
  contexts: ['default']
});

client.onCall(async (call) => {
  await call.answer();

  // Wait for a specific play event
  const action = await call.play([{ type: 'tts', text: 'Hello!' }]);
  const event = await call.waitFor(
    'calling.call.play',
    (e) => e.params.state === 'finished',
    30_000
  );
  console.log(`Play finished: ${JSON.stringify(event.params)}`);
});

await client.run();
```