public static async Task <JsonRpcSession> CreateAsync( Optional <Func <CancellationToken, Task <PinnedRemotableDataScope> > > getSnapshotAsync, object callbackTarget, Stream serviceStream, Stream snapshotStreamOpt, CancellationToken cancellationToken) { var snapshot = getSnapshotAsync.Value == null ? null : await getSnapshotAsync.Value(cancellationToken).ConfigureAwait(false); JsonRpcSession session; try { session = new JsonRpcSession(snapshot, callbackTarget, serviceStream, snapshotStreamOpt, cancellationToken); } catch { snapshot?.Dispose(); throw; } try { await session.InitializeAsync().ConfigureAwait(false); } catch when(!cancellationToken.IsCancellationRequested) { // The session disposes of itself when cancellation is requested. session.Dispose(); throw; } return(session); }
public static async Task <JsonRpcSession> CreateAsync( PinnedRemotableDataScope snapshot, Stream snapshotStream, object callbackTarget, Stream serviceStream, CancellationToken cancellationToken) { var session = new JsonRpcSession(snapshot, snapshotStream, callbackTarget, serviceStream, cancellationToken); await session.InitializeAsync().ConfigureAwait(false); return(session); }