# AsyncObservableExtensions.SubscribeAsync(IAsyncObservable&lt;T&gt;, Func&lt;T, StreamSequenceToken, Task&gt;, Func&lt;Exception, Task&gt;, Func&lt;Task&gt;, StreamSequenceToken)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.streams.asyncobservableextensions/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.streams.asyncobservableextensions/methods/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Extensions/AsyncObservableExtensions.cs#L115-L116)

```csharp
public static Task<StreamSubscriptionHandle<T>> SubscribeAsync<T>(this IAsyncObservable<T> obs, Func<T, StreamSequenceToken, Task> onNextAsync, Func<Exception, Task> onErrorAsync, Func<Task> onCompletedAsync, StreamSequenceToken token)
```

Subscribe a consumer to this observable using delegates. This method is a helper for the IAsyncObservable.SubscribeAsync allowing the subscribing class to inline the handler methods instead of requiring an instance of IAsyncObserver.

### Parameters

- `obs` (`IAsyncObservable<T>`): The Observable object.
- `onNextAsync` (`Func<T, StreamSequenceToken, Task>`): Delegate that is called for IAsyncObserver.OnNextAsync.
- `onErrorAsync` (`Func<Exception, Task>`): Delegate that is called for IAsyncObserver.OnErrorAsync.
- `onCompletedAsync` (`Func<Task>`): Delegate that is called for IAsyncObserver.OnCompletedAsync.
- `token` (`StreamSequenceToken`): The stream sequence to be used as an offset to start the subscription from.

### Returns

A promise for a StreamSubscriptionHandle that represents the subscription. The consumer may unsubscribe by using this handle. The subscription remains active for as long as it is not explicitly unsubscribed.

### Exceptions

- `System.ArgumentException`: Thrown if the supplied stream filter function is not suitable. Usually this is because it is not a static method.
