static IEnumerable<object> InvokeInternal(this ISocket socket, IApplication application, IHttpSupport http) { var beginRequest = http.BeginRequest(socket); yield return beginRequest; if (beginRequest.IsFaulted) throw beginRequest.Exception; IRequest request = beginRequest.Result; var invoke = application.InvokeAsync(request); yield return invoke; if (invoke.IsFaulted) throw invoke.Exception; IResponse response = invoke.Result; yield return http.BeginResponse(socket, response); foreach (var obj in response.GetBody()) { var objectToWrite = obj; if (obj is Task) { var task = (obj as Task).AsTaskWithValue(); yield return task; if (task.IsFaulted) throw task.Exception; objectToWrite = task.Result; } socket.WriteObject(objectToWrite); } // HTTP/1.1 support might only close the connection if client wants to //Trace.Write("Closed connection."); socket.Dispose(); }