Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a5ac15a
CancellationTokens.RunAsync: one helper that combines a call token wi…
electricessence Nov 9, 2026
8a785e1
Command terminals take a CancellationToken
electricessence Nov 10, 2026
50c0261
Channel and Dataflow IExecuteReader overloads take a CancellationToken
electricessence Nov 10, 2026
9d1334b
Docs: the command's Async terminals take a token
electricessence Nov 10, 2026
7ae5c2f
Channel IExecuteReader overloads: static transforms, so no closure is…
electricessence Nov 10, 2026
582166f
Tests pass the test's token to terminals that now take one
electricessence Nov 10, 2026
2562976
Tests for the token on every kept async terminal
electricessence Nov 10, 2026
22dedde
ExecuteCombinedAsync: the token is not last by design (the lambda is)…
electricessence Nov 10, 2026
a25773b
LeakRetentionTests: pass the test's token to ToChannelAsync (CA2016)
electricessence Nov 10, 2026
75f8781
TokenTerminalTests: analyzer findings, and each allocation variant me…
electricessence Nov 10, 2026
f4ab263
Tests: build fixes and analyzer findings
electricessence Nov 10, 2026
3146533
TokenTerminalTests: measure the allocation of the iterating and Chann…
electricessence Nov 10, 2026
5228ad3
TokenTerminalTests: the Roslynator findings of the new test files
electricessence Nov 10, 2026
f84db25
Merge origin/master into feat/token-terminals
electricessence Nov 10, 2026
c4d94d4
TokenTerminalTests: one unnecessary null-forgiving operator
electricessence Nov 10, 2026
cce3393
Merge origin/master into feat/token-terminals
electricessence Nov 10, 2026
45f1b22
A literal default now has tests for what it binds to, the null-comman…
electricessence Nov 10, 2026
0d46fc9
Merge origin/master into feat/token-terminals
electricessence Nov 10, 2026
498d8e2
A failing allocation comparison reports the bytes every token variant…
electricessence Nov 10, 2026
bfdbf32
Merge master into feat/token-terminals
electricessence Nov 10, 2026
91ad573
The token terminals follow the vertical style: one parameter per line…
electricessence Nov 10, 2026
094f9ed
The multi-line if and foreach bodies get braces, as the style rule ID…
electricessence Nov 10, 2026
73e9351
The braces added for IDE0011 are indented as the statement they enclose
electricessence Nov 10, 2026
bfb0ded
The else bodies beside the braced if bodies get braces too
electricessence Nov 10, 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
446 changes: 373 additions & 73 deletions Source/Channel/ToChannel.Target.cs

Large diffs are not rendered by default.

173 changes: 143 additions & 30 deletions Source/Channel/ToChannel.cs

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions Source/Core/Core/CancellationTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,79 @@ public static CancellationToken Combine(CancellationToken commandToken, Cancella
linked = CancellationTokenSource.CreateLinkedTokenSource(commandToken, callToken);
return linked.Token;
}

/// <summary>
/// Starts a call under the one token that governs it
/// (see <see cref="Combine"/>) and releases the linked source,
/// if any, when the call ends however it ends.
/// </summary>
/// <remarks>
/// When no linked source is needed,
/// <paramref name="start"/> is returned as it is: no state machine,
/// no allocation, and a synchronous throw from it propagates synchronously.
/// On the linked path a synchronous throw
/// from <paramref name="start"/> becomes a faulted task.
/// Pass a <see langword="static"/> lambda and a state,
/// so a call with no token or one token allocates nothing.
/// </remarks>
/// <param name="commandToken">The command's own token.</param>
/// <param name="callToken">The token passed to the call.</param>
/// <param name="state">
/// The state handed to <paramref name="start"/>.
/// </param>
/// <param name="start">Starts the call with the governing token.</param>
[SuppressMessage(
"Design", "CA1068:CancellationToken parameters must come last")]
public static ValueTask<TResult> RunAsync<TState, TResult>(
CancellationToken commandToken,
CancellationToken callToken,
TState state,
Func<TState, CancellationToken, ValueTask<TResult>> start)
{
CancellationToken token = Combine(
commandToken,
callToken,
out CancellationTokenSource? linked);
return linked is null
? start(state, token)
: Linked(linked, token, state, start);

static async ValueTask<TResult> Linked(
CancellationTokenSource linked,
CancellationToken token,
TState state,
Func<TState, CancellationToken, ValueTask<TResult>> start)
{
using (linked)
return await start(state, token).ConfigureAwait(false);
}
}

/// <inheritdoc cref="RunAsync{TState, TResult}(CancellationToken, CancellationToken, TState, Func{TState, CancellationToken, ValueTask{TResult}})"/>
[SuppressMessage(
"Design", "CA1068:CancellationToken parameters must come last")]
public static ValueTask RunAsync<TState>(
CancellationToken commandToken,
CancellationToken callToken,
TState state,
Func<TState, CancellationToken, ValueTask> start)
{
CancellationToken token = Combine(
commandToken,
callToken,
out CancellationTokenSource? linked);
return linked is null
? start(state, token)
: Linked(linked, token, state, start);

static async ValueTask Linked(
CancellationTokenSource linked,
CancellationToken token,
TState state,
Func<TState, CancellationToken, ValueTask> start)
{
using (linked)
await start(state, token).ConfigureAwait(false);
}
}
}
Loading