Skip to content
Open
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
36 changes: 18 additions & 18 deletions Source/Channel/ChannelPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ namespace Open.Database.Extensions;

// One frame for every member of the package: the guards run at the
// call (the members are not async), then this frame waits for room,
// runs the feed, counts and completes.
// A feed is the only part that differs: where the rows come from.
// runs the source, counts and completes.
// A source is the only part that differs: where the rows come from.
internal static class ChannelPump
{
/// <summary>
/// Writes the rows of a feed to a channel.
/// Writes the rows of a source to a channel.
/// </summary>
/// <param name="feed">Where the rows come from.</param>
/// <param name="source">Where the rows come from.</param>
/// <param name="writer">Where the rows are written.</param>
/// <param name="complete">
/// <see langword="true"/> to complete the writer when the pass ends,
/// with the exception that ended it if there was one.
/// </param>
/// <include file="../Core/Mapped.docs.xml" path="docs/members[@name='token-pass']/*" />
/// <returns>The number of rows handed to the writer.</returns>
public static async ValueTask<long> Run<T, TFeed>(
TFeed feed,
public static async ValueTask<long> Run<T, TSource>(
TSource source,
ChannelWriter<T> writer,
bool complete,
CancellationToken cancellationToken)
where TFeed : struct, IFeed<T>
where TSource : struct, IPumpSource<T>
{
Debug.Assert(writer is not null);

Expand All @@ -34,9 +34,9 @@ public static async ValueTask<long> Run<T, TFeed>(
Exception? error = null;
try
{
// Reached at the call: the feed takes the stream's enumerator
// Reached at the call: the source takes the stream's enumerator
// before its first await, then waits for room (ChannelPump.Open).
return await feed
return await source
.WriteAsync(writer, cancellationToken)
.ConfigureAwait(false);
}
Expand All @@ -53,7 +53,7 @@ public static async ValueTask<long> Run<T, TFeed>(
}

/// <summary>
/// Takes the enumerator of a feed's stream, then waits for room.
/// Takes the enumerator of a source's stream, then waits for room.
/// </summary>
/// <remarks>
/// The enumerator is taken first, synchronously, so a stream that fills
Expand Down Expand Up @@ -144,7 +144,7 @@ public static int TryWriteFrom<T>(
/// <summary>
/// Where the rows of one pass come from.
/// </summary>
internal interface IFeed<T>
internal interface IPumpSource<T>
{
/// <summary>
/// Writes every row to the writer.
Expand All @@ -156,16 +156,16 @@ ValueTask<long> WriteAsync(
}

/// <summary>
/// The buffered feed: Core's chunk stream, read at full speed.
/// The buffered source: Core's chunk stream, read at full speed.
/// </summary>
/// <remarks>
/// The connection is closed when the read ends, however slowly the
/// writer takes the rows. A full target stalls only this loop:
/// the rows wait in the stream's queue.
/// </remarks>
internal readonly struct ChunkFeed<T>(
internal readonly struct ChunkSource<T>(
IAsyncEnumerable<ReadOnlyMemory<T>> chunks)
: IFeed<T>
: IPumpSource<T>
{
public async ValueTask<long> WriteAsync(
ChannelWriter<T> writer,
Expand Down Expand Up @@ -209,16 +209,16 @@ public async ValueTask<long> WriteAsync(
}

/// <summary>
/// The streaming feed: Core's <c>StreamBuffered</c> with a channel of one row.
/// The streaming source: Core's <c>StreamBuffered</c> with a channel of one row.
/// </summary>
/// <remarks>
/// The next row is pulled only after the current one was written, so a
/// full target holds the reader and the connection open.
/// </remarks>
internal readonly struct RowFeed<T>(IAsyncEnumerable<T> rows)
: IFeed<T>
internal readonly struct RowSource<T>(IAsyncEnumerable<T> rows)
: IPumpSource<T>
{
// The stall timeout is Core's: this feed only learns of an expiry
// The stall timeout is Core's: this source only learns of an expiry
// while it waits for room, because a loop that is not pulling cannot
// see it in MoveNextAsync.
public async ValueTask<long> WriteAsync(
Expand Down
2 changes: 1 addition & 1 deletion Source/Channel/ToChannel.Produce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ IAsyncEnumerable<ReadOnlyMemory<T>> chunks
// fault is read so that a caller who drops the count never has it
// reported as unobserved. A caller who awaits it still sees it.
readCount = ChannelPump
.Run<T, ChunkFeed<T>>(
.Run<T, ChunkSource<T>>(
new(chunks),
channel.Writer,
complete: true,
Expand Down
2 changes: 1 addition & 1 deletion Source/Channel/ToChannel.Streaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static ValueTask<long> ToChannelHoldingConnection<T>(
Contract.EndContractBlock();

cancellationToken.ThrowIfCancellationRequested();
return ChannelPump.Run<T, RowFeed<T>>(
return ChannelPump.Run<T, RowSource<T>>(
new(source.StreamBuffered(stallTimeout, 1, cancellationToken)),
writer,
complete,
Expand Down
2 changes: 1 addition & 1 deletion Source/Channel/ToChannel.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static ValueTask<long> ToChannel<T>(
Contract.EndContractBlock();

cancellationToken.ThrowIfCancellationRequested();
return ChannelPump.Run<T, ChunkFeed<T>>(
return ChannelPump.Run<T, ChunkSource<T>>(
new(source.ToPooledBufferStream(cancellationToken)),
writer,
complete,
Expand Down
38 changes: 19 additions & 19 deletions Source/Dataflow/BlockPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ namespace Open.Database.Extensions;

// One frame for every member of the package: the guards run at the
// call (the members are not async), then this frame checks the target,
// runs the feed, and completes or faults the target.
// A feed is the only part that differs: where the rows come from.
// runs the source, and completes or faults the target.
// A source is the only part that differs: where the rows come from.
internal static class BlockPump
{
/// <summary>
/// Writes the rows of a feed to a block.
/// Writes the rows of a source to a block.
/// </summary>
/// <typeparam name="T">The type of each row.</typeparam>
/// <typeparam name="TFeed">The feed that supplies the rows.</typeparam>
/// <param name="feed">Where the rows come from.</param>
/// <typeparam name="TSource">The source that supplies the rows.</typeparam>
/// <param name="source">Where the rows come from.</param>
/// <param name="target">Where the rows are sent.</param>
/// <param name="complete">
/// <see langword="true"/> to complete the target when the pass ends,
/// or to fault it with the exception that ended the pass.
/// </param>
/// <include file="../Core/Mapped.docs.xml" path="docs/members[@name='token-pass']/*" />
/// <returns>The number of rows the target accepted.</returns>
public static async ValueTask<long> Run<T, TFeed>(
TFeed feed,
public static async ValueTask<long> Run<T, TSource>(
TSource source,
ITargetBlock<T> target,
bool complete,
CancellationToken cancellationToken)
where TFeed : struct, IFeed<T>
where TSource : struct, IPumpSource<T>
{
Debug.Assert(target is not null);

Expand All @@ -36,9 +36,9 @@ public static async ValueTask<long> Run<T, TFeed>(
Exception? error = null;
try
{
// Reached at the call: the feed takes the stream's enumerator
// Reached at the call: the source takes the stream's enumerator
// before its first await, then checks the block (Open).
return await feed
return await source
.WriteAsync(target, cancellationToken)
.ConfigureAwait(false);
}
Expand All @@ -58,7 +58,7 @@ public static async ValueTask<long> Run<T, TFeed>(
}

/// <summary>
/// Takes the enumerator of a feed's stream, then checks the block.
/// Takes the enumerator of a source's stream, then checks the block.
/// </summary>
/// <remarks>
/// The enumerator is taken first, synchronously, so a stream that fills
Expand Down Expand Up @@ -89,7 +89,7 @@ IAsyncEnumerator<TItem> rows
/// <summary>
/// Where the rows of one pass come from.
/// </summary>
internal interface IFeed<T>
internal interface IPumpSource<T>
{
/// <summary>
/// Sends every row to the target.
Expand All @@ -101,16 +101,16 @@ ValueTask<long> WriteAsync(
}

/// <summary>
/// The buffered feed: Core's chunk stream, read at full speed.
/// The buffered source: Core's chunk stream, read at full speed.
/// </summary>
/// <remarks>
/// The connection is closed when the read ends, however slowly the
/// target takes the rows. A full target stalls only this loop:
/// the rows wait in the stream's queue.
/// </remarks>
internal readonly struct ChunkFeed<T>(
internal readonly struct ChunkSource<T>(
IAsyncEnumerable<ReadOnlyMemory<T>> chunks)
: IFeed<T>
: IPumpSource<T>
{
public async ValueTask<long> WriteAsync(
ITargetBlock<T> target,
Expand Down Expand Up @@ -151,17 +151,17 @@ public async ValueTask<long> WriteAsync(
}
}

// The stall timeout is Core's: this feed only learns of an expiry while it waits for the target,
// The stall timeout is Core's: this source only learns of an expiry while it waits for the target,
// because a loop that is not pulling cannot see it in MoveNextAsync.
/// <summary>
/// The streaming feed: Core's <c>StreamBuffered</c> with a channel of one row.
/// The streaming source: Core's <c>StreamBuffered</c> with a channel of one row.
/// </summary>
/// <remarks>
/// The next row is pulled only after the current one was accepted, so a
/// full target holds the reader and the connection open.
/// </remarks>
internal readonly struct RowFeed<T>(IAsyncEnumerable<T> rows)
: IFeed<T>
internal readonly struct RowSource<T>(IAsyncEnumerable<T> rows)
: IPumpSource<T>
{
public async ValueTask<long> WriteAsync(
ITargetBlock<T> target,
Expand Down
6 changes: 3 additions & 3 deletions Source/Dataflow/DataflowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ IAsyncEnumerable<ReadOnlyMemory<T>> chunks
// A failure reaches the block through Fault: the task's own fault is
// read so that it is never reported as unobserved.
_ = BlockPump
.Run<T, ChunkFeed<T>>(
.Run<T, ChunkSource<T>>(
new(chunks),
block,
complete: true,
Expand Down Expand Up @@ -186,7 +186,7 @@ public static ValueTask<long> ToTargetBlock<T>(
Contract.EndContractBlock();

cancellationToken.ThrowIfCancellationRequested();
return BlockPump.Run<T, ChunkFeed<T>>(
return BlockPump.Run<T, ChunkSource<T>>(
new(source.ToPooledBufferStream(cancellationToken)),
target,
complete,
Expand Down Expand Up @@ -283,7 +283,7 @@ public static ValueTask<long> ToTargetBlockHoldingConnection<T>(
Contract.EndContractBlock();

cancellationToken.ThrowIfCancellationRequested();
return BlockPump.Run<T, RowFeed<T>>(
return BlockPump.Run<T, RowSource<T>>(
new(source.StreamBuffered(stallTimeout, 1, cancellationToken)),
target,
complete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static async Task AFullChannel_HoldsTheRun_WithTheCaptureArmed()
Assert.Equal(9, await total);
}

// A cancel while the feed waits for room: nothing ran, and the capture
// A cancel while the source waits for room: nothing ran, and the capture
// is canceled with the call.
[Fact]
public static async Task AFullChannel_CanceledWhileItWaits_CancelsIt()
Expand Down Expand Up @@ -490,7 +490,7 @@ public IAsyncEnumerable<Row> StreamBuffered(
=> throw new NotSupportedException();
}

// A target that closes after the first row: the feed stops and disposes
// A target that closes after the first row: the source stops and disposes
// the stream, and the captured run stops at its next chunk and delivers.
[Theory]
[InlineData(true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static async Task<List<int>> Drain(
}

/// <summary>
/// A source that is not ours: the feeds work on any implementation of
/// A source that is not ours: the pump sources work on any implementation of
/// the interface.
/// </summary>
public sealed class FakeSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static async Task<ChannelRow> ReceiveRow(ISourceBlock<ChannelRow> block,
when (ex.CancellationToken == cts.Token && !Ct.IsCancellationRequested)
{
// The wait here ran out: that is a failure of the test,
// not a cancel the feed reported.
// not a cancel the source reported.
throw new TimeoutException("the channel never ended", ex);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static void TheGuards_ThrowAtTheCall()
.ToChannelHoldingConnection(Unbounded(), Long, Ct)));
}

// The feed adds no timing of its own: the timeout and the token
// The source adds no timing of its own: the timeout and the token
// reach Stream untouched, on a source that is not ours.
[Theory]
[InlineData(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static void TheGuards_ThrowAtTheCall()
.ToTargetBlockHoldingConnection(NewBlock(), Long, Ct)));
}

// The feed adds no timing of its own: the timeout and the token
// The source adds no timing of its own: the timeout and the token
// reach Stream untouched, on a source that is not ours.
[Theory]
[InlineData(false)]
Expand Down