private Task ProcessReceiveRequest(ITransportConnection connection) { Func <Task> initialize = null; // If this transport isn't replacing an existing transport, oldConnection will be null. ITrackingConnection oldConnection = Heartbeat.AddOrUpdateConnection(this); bool newConnection = oldConnection == null; if (IsConnectRequest) { if (_protocolResolver.SupportsDelayedStart(Context.Request)) { // TODO: Ensure delegate continues to use the C# Compiler static delegate caching optimization. initialize = () => connection.Initialize(ConnectionId); } else { Func <Task> connected; if (newConnection) { connected = Connected ?? _emptyTaskFunc; _counters.ConnectionsConnected.Increment(); } else { // Wait until the previous call to Connected completes. // We don't want to call Connected twice connected = () => oldConnection.ConnectTask; } initialize = () => { return(connected().Then((conn, id) => conn.Initialize(id), connection, ConnectionId)); }; } } else if (!SuppressReconnect) { initialize = Reconnected; _counters.ConnectionsReconnected.Increment(); } initialize = initialize ?? _emptyTaskFunc; Func <Task> fullInit = () => initialize().ContinueWith(_connectTcs); return(ProcessMessages(connection, fullInit)); }
private Task ProcessReceiveRequest(ITransportConnection connection) { Func<Task> initialize = null; // If this transport isn't replacing an existing transport, oldConnection will be null. ITrackingConnection oldConnection = Heartbeat.AddOrUpdateConnection(this); bool newConnection = oldConnection == null; if (IsConnectRequest) { if (_protocolResolver.SupportsDelayedStart(Context.Request)) { // TODO: Ensure delegate continues to use the C# Compiler static delegate caching optimization. initialize = () => connection.Initialize(ConnectionId); } else { Func<Task> connected; if (newConnection) { connected = Connected ?? _emptyTaskFunc; _counters.ConnectionsConnected.Increment(); } else { // Wait until the previous call to Connected completes. // We don't want to call Connected twice connected = () => oldConnection.ConnectTask; } initialize = () => { return connected().Then((conn, id) => conn.Initialize(id), connection, ConnectionId); }; } } else if (!SuppressReconnect) { initialize = Reconnected; _counters.ConnectionsReconnected.Increment(); } initialize = initialize ?? _emptyTaskFunc; Func<Task> fullInit = () => initialize().ContinueWith(_connectTcs); return ProcessMessages(connection, fullInit); }