public Task ProcessRequest(ITransportConnection connection) { Connection = connection; if (IsSendRequest) { return(ProcessSendRequest()); } else if (IsAbortRequest) { return(Connection.Abort(ConnectionId)); } else { if (IsConnectRequest) { return(ProcessConnectRequest(connection)); } else if (MessageId != null) { if (IsReconnectRequest && Reconnected != null) { // Return a task that completes when the reconnected event task & the receive loop task are both finished return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection, Completed)); } return(ProcessReceiveRequest(connection)); } } return(null); }
public Task ProcessRequest(ITransportConnection connection) { Connection = connection; if (IsSendRequest) { return(ProcessSendRequest()); } else if (IsAbortRequest) { return(Connection.Abort(ConnectionId)); } else { InitializePersistentState(); if (IsConnectRequest) { return(ProcessConnectRequest(connection)); } else if (MessageId != null) { if (IsReconnectRequest && Reconnected != null) { // Return a task that completes when the reconnected event task & the receive loop task are both finished Func <Task> reconnected = () => Reconnected().Then(() => _counters.ConnectionsReconnected.Increment()); return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, reconnected, connection, Completed)); } return(ProcessReceiveRequest(connection)); } } return(null); }
protected Task ProcessRequestCore(ITransportConnection connection) { Connection = connection; if (Context.Request.Url.LocalPath.EndsWith("/send")) { return(ProcessSendRequest()); } else if (IsAbortRequest) { return(Connection.Abort()); } else { if (IsConnectRequest) { if (Connected != null) { // Return a task that completes when the connected event task & the receive loop task are both finished return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Connected, connection)); } return(ProcessReceiveRequest(connection)); } if (Reconnected != null) { // Return a task that completes when the reconnected event task & the receive loop task are both finished return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection)); } return(ProcessReceiveRequest(connection)); } }
private Task ProcessConnectRequest(ITransportConnection connection) { HeartBeat.AddConnection(this); if (Connected != null) { // Return a task that completes when the connected event task & the receive loop task are both finished return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Connected, connection)); } return(ProcessReceiveRequest(connection)); }
protected Task ProcessRequestCore(ITransportConnection connection) { Connection = connection; if (Context.Request.Url.LocalPath.EndsWith("/send", StringComparison.OrdinalIgnoreCase)) { return(ProcessSendRequest()); } else if (IsAbortRequest) { return(Connection.Abort(ConnectionId)); } else { InitializePersistentState(); if (IsConnectRequest) { if (Connected != null) { // Return a task that completes when the connected event task & the receive loop task are both finished bool newConnection = Heartbeat.AddConnection(this); // The connected callback Func <Task> connected = () => { if (newConnection) { return(Connected().Then(() => _counters.ConnectionsConnected.Increment())); } return(TaskAsyncHelper.Empty); }; return(TaskAsyncHelper.Interleave(ProcessReceiveRequestWithoutTracking, connected, connection, Completed)); } return(ProcessReceiveRequest(connection)); } if (Reconnected != null) { // Return a task that completes when the reconnected event task & the receive loop task are both finished Func <Task> reconnected = () => Reconnected().Then(() => _counters.ConnectionsReconnected.Increment()); return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, reconnected, connection, Completed)); } return(ProcessReceiveRequest(connection)); } }
public Task ProcessRequest(IReceivingConnection connection) { // This will only be called on the first request so we return a task that fires on connect var taskCompletionSource = new TaskCompletionSource <object>(); _webSocketConnection.OnOpen = () => { if (Connected != null) { TaskAsyncHelper.Interleave(ProcessMessages, Connected, connection).ContinueWith(taskCompletionSource); } else { // Just process messages if there's no handler ProcessMessages(connection).ContinueWith(taskCompletionSource); } }; _webSocketConnection.OnClose = () => { _disconnected = true; if (Disconnected != null) { Disconnected().Catch(); } }; _webSocketConnection.OnError = ex => { _disconnected = true; if (Error != null) { Error(ex).Catch(); } }; _webSocketConnection.OnMessage = data => { if (Received != null) { Received(data).Catch(); } }; return(taskCompletionSource.Task); }
protected Task ProcessRequestCore(ITransportConnection connection) { Connection = connection; if (Context.Request.Url.LocalPath.EndsWith("/send")) { return(ProcessSendRequest()); } else if (IsAbortRequest) { return(Connection.Abort(ConnectionId)); } else { if (IsConnectRequest) { if (Connected != null) { // Return a task that completes when the connected event task & the receive loop task are both finished bool newConnection = HeartBeat.AddConnection(this); return(TaskAsyncHelper.Interleave(ProcessReceiveRequestWithoutTracking, () => { if (newConnection) { return Connected().Then(() => _counters.ConnectionsConnected.Increment()); } return TaskAsyncHelper.Empty; } , connection, Completed)); } return(ProcessReceiveRequest(connection)); } if (Reconnected != null) { // Return a task that completes when the reconnected event task & the receive loop task are both finished Func <Task> reconnected = () => Reconnected().Then(() => _counters.ConnectionsReconnected.Increment()); return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, reconnected, connection, Completed)); } return(ProcessReceiveRequest(connection)); } }
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)); }