/// <summary> /// Asynchronously flush the writer. /// </summary> /// <returns>Task which represents the pending flush operation.</returns> /// <remarks>The method should not throw directly if the flush operation itself fails, it should instead return a faulted task.</remarks> internal Task FlushAsync() { DebugUtils.CheckNoExternalCallers(); this.AssertAsynchronous(); return(TaskUtils.GetTaskForSynchronousOperationReturningTask( () => { if (this.rawValueWriter != null) { this.rawValueWriter.Flush(); } Debug.Assert(this.asynchronousOutputStream != null, "In async writing we must have the async buffered stream."); return this.asynchronousOutputStream.FlushAsync(); }) .FollowOnSuccessWithTask((asyncBufferedStreamFlushTask) => this.messageOutputStream.FlushAsync())); }
/// <summary> /// Asynchronously flush the writer. /// </summary> /// <returns>Task which represents the pending flush operation.</returns> /// <remarks>The method should not throw directly if the flush operation itself fails, it should instead return a faulted task.</remarks> internal Task FlushAsync() { DebugUtils.CheckNoExternalCallers(); this.AssertAsynchronous(); return(TaskUtils.GetTaskForSynchronousOperationReturningTask( () => { if (this.textWriter != null) { // The TextWriter.Flush (Which is in fact StreamWriter.Flush) will call the underlying Stream.Flush. // In the async case the underlying stream is the async buffered stream, which ignores Flush call. this.textWriter.Flush(); } Debug.Assert(this.asynchronousOutputStream != null, "In async writing we must have the async buffered stream."); return this.asynchronousOutputStream.FlushAsync(); }) .FollowOnSuccessWithTask((asyncBufferedStreamFlushTask) => this.messageOutputStream.FlushAsync())); }