private void ContinueWriteResponseAsync( byte[] response, Action onSuccess, Action<Exception> onError, Action onCompleted) { if (_asyncWriter == null) _asyncWriter = new AsyncQueuedBufferWriter( _currentOutputStream, () => DisposeStreamAndCloseConnection("Close connection error")); _asyncWriter.Append( response, errorIfAny => { if (errorIfAny == null) onSuccess(); else onError(errorIfAny); onCompleted(); }); }