private Task ProcessConnectRequest(ITransportConnection connection) { if (Connected != null) { bool newConnection = HeartBeat.AddConnection(this); // Return a task that completes when the connected event task & the receive loop task are both finished return(TaskAsyncHelper.Interleave(ProcessReceiveRequestWithoutTracking, () => { if (newConnection) { return Connected(); } return TaskAsyncHelper.Empty; }, connection, Completed)); } return(ProcessReceiveRequest(connection)); }
private Task ProcessReceiveRequest(ITransportConnection connection, Action postReceive = null) { HeartBeat.AddConnection(this); HeartBeat.MarkConnection(this); Action afterReceive = () => { if (TransportConnected != null) { TransportConnected().Catch(); } if (postReceive != null) { postReceive(); } }; return(InitializeResponse(connection) .Then((c, pr) => ProcessMessages(c, pr), connection, afterReceive)); }
private Task ProcessReceiveRequest(ITransportConnection connection, Action postReceive = null) { HeartBeat.AddConnection(this); return(ProcessReceiveRequestWithoutTracking(connection, postReceive)); }