Skip to content

Commit

Permalink
Fix null handling for source arg
Browse files Browse the repository at this point in the history
  • Loading branch information
azyobuzin committed Oct 13, 2020
1 parent 98d8397 commit 160e940
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ValueTask DisposeAsync()

Task IDataflowBlock.Completion => throw new NotImplementedException();

DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept)
DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T>? source, bool consumeToAccept)
{
if (source != null && source != this._source) throw new ArgumentException("Unexpected source.");
if (!messageHeader.IsValid) throw new ArgumentException("messageHeader is not valid.");
Expand Down
4 changes: 2 additions & 2 deletions src/BiDaFlow/Blocks/EncapsulatingPropagatorBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void ReleaseReservation(DataflowMessageHeader messageHeader, ITargetBlock
public bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target)
=> this._terminal.ReserveMessage(messageHeader, target);

public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, TInput messageValue, ISourceBlock<TInput> source, bool consumeToAccept)
=> this._entrance.OfferMessage(messageHeader, messageValue, new ProxySourceBlock<TInput>(this, source), consumeToAccept);
public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, TInput messageValue, ISourceBlock<TInput>? source, bool consumeToAccept)
=> this._entrance.OfferMessage(messageHeader, messageValue, source != null ? new ProxySourceBlock<TInput>(this, source) : null, consumeToAccept);

public bool TryReceive(Predicate<TOutput>? filter, out TOutput item)
{
Expand Down
4 changes: 2 additions & 2 deletions src/BiDaFlow/Blocks/EncapsulatingTargetBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public EncapsulatingTargetBlock(ITargetBlock<T> entrance, IDataflowBlock termina

public void Fault(Exception exception) => this._entrance.Fault(exception);

public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept)
=> this._entrance.OfferMessage(messageHeader, messageValue, new ProxySourceBlock<T>(this, source), consumeToAccept);
public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T>? source, bool consumeToAccept)
=> this._entrance.OfferMessage(messageHeader, messageValue, source != null ? new ProxySourceBlock<T>(this, source) : null, consumeToAccept);
}
}
3 changes: 3 additions & 0 deletions src/BiDaFlow/Blocks/ProxySourceBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ internal sealed class ProxySourceBlock<T> : ISourceBlock<T>

public ProxySourceBlock(ITargetBlock<T> targetWrapper, ISourceBlock<T> source)
{
if (targetWrapper == null) throw new ArgumentNullException(nameof(targetWrapper));
if (source == null) throw new ArgumentNullException(nameof(source));

this._targetWrapper = targetWrapper;
this._source = source;
}
Expand Down
4 changes: 4 additions & 0 deletions src/BiDaFlow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Fix wrong null handling in the classes encapsulating `ITargetBlock`

## [0.2.0-alpha1] - 2020-10-13
### Added
- Add simple encapulation methods
Expand Down

0 comments on commit 160e940

Please sign in to comment.