# TestingUtils.WaitUntilAsync(Func&lt;bool, CancellationToken, Task&lt;bool&gt;&gt;, TimeSpan, TimeSpan?, CancellationToken, string?)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.utils.testingutils/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.utils.testingutils/methods/)

[Source](https://github.com/dotnet/orleans/blob/b7a9e3e1c9c54b3cec3a467c5734bf7744541bcf/src/Orleans.TestingHost/Utils/TestingUtils.cs#L83-L86)

```csharp
public static Task WaitUntilAsync(Func<bool, CancellationToken, Task<bool>> predicate, TimeSpan timeout, TimeSpan? delayOnFail = null, CancellationToken cancellationToken = default(CancellationToken), string? predicateExpression = null)
```

Run the predicate until it succeeds or times out.

### Parameters

- `predicate` (`Func<bool, CancellationToken, Task<bool>>`): The predicate to run. The first argument indicates the final attempt, allowing the predicate to throw a detailed assertion failure. The token is cancelled when the deadline expires or cancellation is requested.
- `timeout` (`TimeSpan`): The timeout value.
- `delayOnFail` (`TimeSpan?`): The delay before retrying after an unsuccessful attempt.
- `cancellationToken` (`CancellationToken`): The cancellation token.
- `predicateExpression` (`string?`): The expression supplied for `predicate`.

### Returns

A task representing the operation.

### Exceptions

- `System.TimeoutException`: The predicate did not succeed before the timeout elapsed.
