Class PipeWriter<T>
- Namespace
- MarymoorStudios.Core.Rpc
- Assembly
- MarymoorStudios.Core.Rpc.dll
Capability for writing an ordered sequence of items to a pipe.
public abstract class PipeWriter<T> : IPromiseDisposable, IDisposable
Type Parameters
T
- Inheritance
-
PipeWriter<T>
- Implements
- Inherited Members
Constructors
PipeWriter()
protected PipeWriter()
Methods
Abort()
Promptly aborts the sequence.
public abstract void Abort()
Remarks
Write initiated abort is best-effort transmitted across the transport to the Reader. If the transport has itself been aborted then the abort signal is discarded (but the Reader will see an abort from the transport). Any items in the pipe that cannot be transmitted before the transport has been torn down are immediately released.
Close(Exception?)
Terminates the sequence.
public abstract Promise Close(Exception? error = null)
Parameters
error
ExceptionAn optional error to terminate the sequence with.
Returns
- Promise
A promise that resolves when the Reader has seen the entire sequence.
Remarks
If the sequence is terminated without an error (a successful termination) the Reader will see an End of Sequence (EOS). If an error is provided, the Reader will eventually see that error as the result of a call to Read().
Dispose()
Promptly terminates the sequence.
public void Dispose()
Remarks
If the sequence is already terminated or a graceful Close(Exception?) can be promptly transmitted on the transport, it is done. Otherwise, an Abort() occurs. If any untransmitted items cannot be promptly transmitted they are released without being transmitted and the termination becomes an Abort().
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
DisposeAsync()
Asynchronously terminates the sequence.
public Promise DisposeAsync()
Returns
Remarks
If the sequence is not already terminated, a graceful Close(Exception?) is performed. The result then resolves after a graceful termination acknowledgement is received from the Reader (indicating that all items have been received including the graceful termination signal).
If the transport is torn down before all pending items can be transmitted, or before a graceful termination acknowledgement has been received from the Reader, then any untransmitted items are released without being transmitted and the termination becomes an Abort().
DisposeAsyncCore()
protected virtual Promise DisposeAsyncCore()
Returns
Flush()
Returns a promise that resolves when flow control would allow additional writes without buffering.
public abstract Promise Flush()
Returns
Remarks
If there is no flow control pressure the return value will be promptly resolved.
Write(ref T)
Writes a item to the pipe.
public abstract void Write(ref T item)
Parameters
item
TThe item to be written.
Remarks
On a successful return, ownership of the provided item is transferred to the pipe. Buffers successfully written to the pipe but never delivered to a reader (e.g. because the Reader is disposed or the transport is terminated) will be disposed by the Pipe itself. The input l-value is "consumed".
The error EndOfSequenceException occurs when the Writer comes know that the Reader has been disposed before the EOS has been written. This error will be thrown repeatedly on all subsequent writes after this point. The Writer should gracefully terminate production.
If the sequence is cancelled by the Reader (optionally with an error),
OperationCanceledException) (or that error) will be returned by the next call to
Write(ref T) or Flush() after the Writer
If the sequence is aborted by the Reader or the underlying pipe transport, a call to Write(ref T) or Flush() will yield an AbortedException. Some items in the sequence may have been lost in the event of an abort.