private bool TryGetStreamingEnumerator(HubConnectionContext connection, string invocationId, HubMethodDescriptor hubMethodDescriptor, object result, out IAsyncEnumerator <object> enumerator) { if (result != null) { if (hubMethodDescriptor.IsObservable) { enumerator = hubMethodDescriptor.FromObservable(result, CreateCancellation()); return(true); } if (hubMethodDescriptor.IsChannel) { enumerator = hubMethodDescriptor.FromChannel(result, CreateCancellation()); return(true); } } enumerator = null; return(false); CancellationToken CreateCancellation() { var streamCts = new CancellationTokenSource(); connection.ActiveRequestCancellationSources.TryAdd(invocationId, streamCts); return(CancellationTokenSource.CreateLinkedTokenSource(connection.ConnectionAborted, streamCts.Token).Token); } }
private bool TryGetStreamingEnumerator(HubConnectionContext connection, string invocationId, HubMethodDescriptor hubMethodDescriptor, object result, out IAsyncEnumerator <object> enumerator, ref CancellationTokenSource streamCts) { if (result != null) { if (hubMethodDescriptor.IsChannel) { if (streamCts == null) { streamCts = CancellationTokenSource.CreateLinkedTokenSource(connection.ConnectionAborted); } connection.ActiveRequestCancellationSources.TryAdd(invocationId, streamCts); enumerator = hubMethodDescriptor.FromChannel(result, streamCts.Token); return(true); } } enumerator = null; return(false); }