Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d784109
Remove the parameter direction from the fluent expressive-command chain.
electricessence Dec 2, 2026
267014d
Make the public Param input-only.
electricessence Dec 2, 2026
0d883a4
Read output parameters into a model with ExecuteOutputAsync.
electricessence Dec 2, 2026
dfcd80e
Make the removed fluent direction and type-only shapes compile errors.
electricessence Dec 2, 2026
1764460
Output parameters: DateOnly and TimeOnly, legacy datetime documented,…
electricessence Dec 2, 2026
dab8030
Narrow the obsolete-member exemption to the four chain overloads, and…
electricessence Dec 2, 2026
7bcd292
Merge origin/master into output-params.
electricessence Dec 2, 2026
590948b
Output parameters: review fixes in docs, messages, tests and analyzer…
electricessence Dec 2, 2026
f298dff
Document that a char output reads one character.
electricessence Dec 2, 2026
8e2f961
Docs: share the output-parameter text through Output.docs.xml.
electricessence Dec 2, 2026
bb0d436
Samples for output parameters.
electricessence Dec 2, 2026
627677c
Docs: complete the shared output text and tidy the samples.
electricessence Dec 2, 2026
e2aaa76
Samples: one connection factory across the output snippets.
electricessence Dec 2, 2026
8a3c6fc
Captures: read output parameters beside rows (C1)
electricessence Dec 2, 2026
6e5b1ef
Docs: captures, output parameters beside rows
electricessence Dec 2, 2026
af80660
Samples: pass the token to WriteLineAsync in the stream sample.
electricessence Dec 2, 2026
43640d4
Captures: tests on every path, and the Channel and Dataflow members a…
electricessence Dec 2, 2026
59fb812
Captures: fixes from the C1 review, and tests for the decided cases
electricessence Dec 2, 2026
89bb16c
Tests: the unobserved-fault check waits past its control
electricessence Dec 2, 2026
924cac5
Merge master (962e080a) into output-params
electricessence Dec 2, 2026
fc64167
Channel and Dataflow pumps: owner review of PR 290, with tests
electricessence Dec 2, 2026
f06c108
Docs: capture wording after the final review
electricessence Dec 2, 2026
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
135 changes: 110 additions & 25 deletions Source/Channel/ChannelPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@ 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 (!await writer
.WaitToWriteAsync(cancellationToken)
.ConfigureAwait(false))
{
return 0;
}

// Reached at the call: the feed takes the stream's enumerator
// before its first await, then waits for room (ChannelPump.Open).
return await feed
.WriteAsync(writer, cancellationToken)
.ConfigureAwait(false);
Expand All @@ -60,6 +52,84 @@ internal static async ValueTask<long> Run<T, TFeed>(
}
}

/// <summary>
/// Takes the enumerator of a feed's stream, then waits for room.
/// </summary>
/// <remarks>
/// The enumerator is taken first, synchronously, so a stream that fills
/// captures claims them at the call; it starts nothing until the first
/// pull. The wait comes before that pull, so a full target never gets
/// a command run or a connection opened for it.
/// </remarks>
/// <returns>
/// The enumerator, or <see langword="null"/> when the writer was closed
/// before the first row (the enumerator is disposed: nothing read).
/// </returns>
// Not async: with room now, it returns the enumerator with no frame and
// nothing allocated. Only a wait, a closed writer or a failure goes on.
internal static ValueTask<IAsyncEnumerator<TItem>?> Open<T, TItem>(
IAsyncEnumerable<TItem> stream,
ChannelWriter<T> writer,
CancellationToken cancellationToken)
{
IAsyncEnumerator<TItem> rows
= stream.GetAsyncEnumerator(cancellationToken);
ValueTask<bool> wait;
try
{
wait = writer.WaitToWriteAsync(cancellationToken);
}
catch (Exception ex)
{
return OpenAsync(rows, new(Task.FromException<bool>(ex)));
}

if (!wait.IsCompletedSuccessfully) return OpenAsync(rows, wait);

return wait.Result
? new(rows)
: CloseAsync(rows);
}

static async ValueTask<IAsyncEnumerator<TItem>?> OpenAsync<TItem>(
IAsyncEnumerator<TItem> rows,
ValueTask<bool> wait)
{
bool room;
try
{
room = await wait.ConfigureAwait(false);
}
catch
{
try
{
await rows.DisposeAsync()
.ConfigureAwait(false);
}
catch
{
// The wait's exception is the one the pass reports (a cancel
// stays a cancel): a failed dispose must not replace it.
}

throw;
}

return room
? rows
: await CloseAsync(rows)
.ConfigureAwait(false);
}

static async ValueTask<IAsyncEnumerator<TItem>?> CloseAsync<TItem>(
IAsyncEnumerator<TItem> rows)
{
await rows.DisposeAsync()
.ConfigureAwait(false);
return null;
}

/// <summary>
/// Writes rows from a position of a chunk until the writer has no room.
/// </summary>
Expand Down Expand Up @@ -109,11 +179,18 @@ public async ValueTask<long> WriteAsync(
ChannelWriter<T> writer,
CancellationToken cancellationToken)
{
IAsyncEnumerator<ReadOnlyMemory<T>>? chunked
= await ChannelPump.Open(chunks, writer, cancellationToken)
.ConfigureAwait(false);
if (chunked is null) return 0;

await using var _ = chunked.ConfigureAwait(false);

long count = 0;
await foreach (ReadOnlyMemory<T> chunk in chunks
.WithCancellation(cancellationToken)
while (await chunked.MoveNextAsync()
.ConfigureAwait(false))
{
ReadOnlyMemory<T> chunk = chunked.Current;
int i = 0;
while (true)
{
Expand All @@ -122,11 +199,12 @@ public async ValueTask<long> WriteAsync(
i = next;
if (i == chunk.Length) break;

// Full, or closed: wait for room, then write the same row.
// Leaving the loop disposes the stream, which cancels the
// query and releases every chunk.
if (!await writer
.WaitToWriteAsync(cancellationToken)
// Full, or closed: wait for room, then write the same
// row. Leaving the loop disposes the stream, which
// cancels the query and releases every chunk (a query
// with a capture stops at its next chunk instead, and
// fills the capture).
if (!await writer.WaitToWriteAsync(cancellationToken)
.ConfigureAwait(false))
{
return count;
Expand Down Expand Up @@ -166,24 +244,31 @@ public async ValueTask<long> WriteAsync(
: null;
CancellationToken wait = link?.Token ?? cancellationToken;

IAsyncEnumerator<T>? pulled
= await ChannelPump.Open(rows, writer, cancellationToken)
.ConfigureAwait(false);
if (pulled is null) return 0;

await using var _ = pulled.ConfigureAwait(false);

long count = 0;
await foreach (T row in rows
.WithCancellation(cancellationToken)
while (await pulled.MoveNextAsync()
.ConfigureAwait(false))
{
T row = pulled.Current;
while (!writer.TryWrite(row))
{
// Without a link there is no signal that can fire:
// the plain wait, nothing created.
bool room = link is null
? await writer
.WaitToWriteAsync(cancellationToken)
? await writer.WaitToWriteAsync(cancellationToken)
.ConfigureAwait(false)
: await WaitAsync(
writer,
signal!,
wait,
cancellationToken).ConfigureAwait(false);
writer,
signal!,
wait,
cancellationToken)
.ConfigureAwait(false);

if (!room) return count;
}
Expand Down
Loading
Loading