public async Task <DuplexStreamingResult <bool, bool> > Connect() { var streaming = GetDuplexStreamingContext <bool, bool>(); var id = ConnectionContext.GetConnectionId(Context); var cancellationTokenSource = ConnectionContext.Register(id); try { // send to connect complete. await streaming.WriteAsync(true).ConfigureAwait(false); // wait client disconnect. // if client send complete event, safe unsubscribe of heartbeat. await streaming.MoveNext(); } catch (RpcException) { // ok, cancelled. } finally { ConnectionContext.Unregister(id); cancellationTokenSource.Cancel(); } return(streaming.Result()); }
public async Task <DuplexStreamingResult <Nil, Nil> > Connect() { var streaming = GetDuplexStreamingContext <Nil, Nil>(); var id = ConnectionContext.GetConnectionId(Context); var cancellationTokenSource = ConnectionContext.Register(id); try { // send to connect complete. await streaming.WriteAsync(Nil.Default).ConfigureAwait(false); // receive client hearbeat ping. while (await streaming.MoveNext().ConfigureAwait(false)) { } } catch (RpcException) { // ok, cancelled. } finally { ConnectionContext.Unregister(id); cancellationTokenSource.Cancel(); } return(streaming.Result()); }