# IBroadcastChannelSubscription.Attach(Func&lt;T, CancellationToken, Task&gt;, Func&lt;Exception, CancellationToken, Task&gt;)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.broadcastchannel/orleans.broadcastchannel.ibroadcastchannelsubscription/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.broadcastchannel/orleans.broadcastchannel.ibroadcastchannelsubscription/methods/)

[Source](https://github.com/dotnet/orleans/blob/1644940b035c7bdf215a4fd7135757c06bcfe9ec/src/Orleans.BroadcastChannel/BroadcastChannelSubscription.cs#L41-L43)

```csharp
public virtual Task Attach<T>(Func<T, CancellationToken, Task> onPublished, Func<Exception, CancellationToken, Task>? onError = null)
```

Attaches cancellation-aware callbacks to the channel subscription.

### Parameters

- `onPublished` (`Func<T, CancellationToken, Task>`): The callback invoked when an element is published.
- `onError` (`Func<Exception, CancellationToken, Task>`): The callback invoked when delivery fails.

### Returns

A `System.Threading.Tasks.Task` representing the operation.
