Akka.Streams.Implementation.IO.OutputStreamSubscriber.Receive C# (CSharp) Method

Receive() protected method

protected Receive ( object message ) : bool
message object
return bool
        protected override bool Receive(object message)
        {
            return message.Match()
                .With<OnNext>(next =>
                {
                    try
                    {
                        var bytes = next.Element as ByteString;
                        //blocking write
                        _outputStream.Write(bytes.ToArray(), 0, bytes.Count);
                        _bytesWritten += bytes.Count;
                        if (_autoFlush)
                            _outputStream.Flush();
                    }
                    catch (Exception ex)
                    {
                        _completionPromise.TrySetResult(new IOResult(_bytesWritten, Result.Failure<NotUsed>(ex)));
                        Cancel();
                    }
                })
                .With<OnError>(error =>
                {
                    _log.Error(error.Cause,
                        $"Tearing down OutputStreamSink due to upstream error, wrote bytes: {_bytesWritten}");
                    _completionPromise.TrySetResult(new IOResult(_bytesWritten, Result.Failure<NotUsed>(error.Cause)));
                    Context.Stop(Self);
                })
                .With<OnComplete>(() =>
                {
                    Context.Stop(Self);
                    _outputStream.Flush();
                })
                .WasHandled;
        }