Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Source/Channel/ChannelPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ internal static class ChannelPump
/// <see langword="true"/> to complete the writer when the pass ends,
/// with the exception that ended it if there was one.
/// </param>
/// <param name="waitFirst">
/// <see langword="true"/> to wait for room before the feed starts,
/// so a full target never gets a command run or a connection opened for it.
/// </param>
/// <param name="cancellationToken">Stops the pass.</param>
/// <returns>The number of rows handed to the writer.</returns>
internal static async ValueTask<long> Run<T, TFeed>(
TFeed feed,
ChannelWriter<T> writer,
bool complete,
bool waitFirst,
CancellationToken cancellationToken)
where TFeed : struct, IFeed<T>
{
Expand All @@ -39,11 +34,12 @@ internal static async ValueTask<long> Run<T, TFeed>(
Exception? error = null;
try
{
// Wait for room before the feed starts, so a full target never
// gets a command run or a connection opened for it.
// Closed before the first row: nothing to write, nothing read.
if (waitFirst
&& !await writer
.WaitToWriteAsync(cancellationToken)
.ConfigureAwait(false))
if (!await writer
.WaitToWriteAsync(cancellationToken)
.ConfigureAwait(false))
{
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions Source/Channel/ToChannel.Produce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,13 @@ IAsyncEnumerable<ReadOnlyMemory<T>> chunks
AllowSynchronousContinuations = false,
});

// The channel is empty: there is room, so the first wait is skipped.
// A failure reaches the channel through Complete; the task
// is dropped unobserved unless the caller asked for the count.
readCount = ChannelPump
.Run<T, ChunkFeed<T>>(
new(chunks),
channel.Writer,
complete: true,
waitFirst: false,
cancellationToken)
.AsTask();

Expand Down
1 change: 0 additions & 1 deletion Source/Channel/ToChannel.Streaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public static ValueTask<long> ToChannelHoldingConnection<T>(
new(source.StreamBuffered(stallTimeout, 1, cancellationToken)),
writer,
complete,
waitFirst: true,
cancellationToken);
}

Expand Down
1 change: 0 additions & 1 deletion Source/Channel/ToChannel.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public static ValueTask<long> ToChannel<T>(
new(source.ToPooledBufferStream(cancellationToken)),
writer,
complete,
waitFirst: true,
cancellationToken);
}

Expand Down
10 changes: 3 additions & 7 deletions Source/Dataflow/BlockPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ internal static class BlockPump
/// <see langword="true"/> to complete the target when the pass ends,
/// or to fault it with the exception that ended the pass.
/// </param>
/// <param name="checkOpen">
/// <see langword="true"/> to stop before the feed starts when the
/// target is already finished, so no command is run for it.
/// </param>
/// <param name="cancellationToken">Stops the pass.</param>
/// <returns>The number of rows the target accepted.</returns>
internal static async ValueTask<long> Run<T, TFeed>(
TFeed feed,
ITargetBlock<T> target,
bool complete,
bool checkOpen,
CancellationToken cancellationToken)
where TFeed : struct, IFeed<T>
{
Expand All @@ -42,8 +37,9 @@ internal static async ValueTask<long> Run<T, TFeed>(
try
{
// A block has no way to ask for room: only a row can tell.
// A block that is already finished is the one thing known now.
if (checkOpen && target.Completion.IsCompleted)
// A block that is already finished is the one thing known now,
// and no command is run for it.
if (target.Completion.IsCompleted)
return 0;

return await feed
Expand Down
3 changes: 0 additions & 3 deletions Source/Dataflow/DataflowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ IAsyncEnumerable<ReadOnlyMemory<T>> chunks
new(chunks),
block,
complete: true,
checkOpen: false,
cancellationToken)
.AsTask()
.ContinueWith(
Expand Down Expand Up @@ -191,7 +190,6 @@ public static ValueTask<long> ToTargetBlock<T>(
new(source.ToPooledBufferStream(cancellationToken)),
target,
complete,
checkOpen: true,
cancellationToken);
}

Expand Down Expand Up @@ -289,7 +287,6 @@ public static ValueTask<long> ToTargetBlockHoldingConnection<T>(
new(source.StreamBuffered(stallTimeout, 1, cancellationToken)),
target,
complete,
checkOpen: true,
cancellationToken);
}

Expand Down