Skip to content

Commit ea24967

Browse files
committed
Rename the method for public use
1 parent ed2db82 commit ea24967

11 files changed

+46
-18
lines changed

src/DotNext.Tests/Threading/Tasks/ValueTaskCompletionSourceTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,29 @@ public static async Task CanceledToken()
167167
var task = source.CreateTask(InfiniteTimeSpan, new(true)).AsTask();
168168
await ThrowsAsync<OperationCanceledException>(Func.Constant(task));
169169
}
170+
171+
[Fact]
172+
public static async Task LazyCompletion()
173+
{
174+
var source = new TestCompletionSource();
175+
var task = source.CreateTask(InfiniteTimeSpan, CancellationToken.None).AsTask();
176+
177+
True(source.TrySetResult(string.Empty, completionToken: null, e: null, out var resumable));
178+
True(resumable);
179+
Same(string.Empty, source.CompletionData);
180+
False(task.IsCompleted);
181+
182+
source.NotifyConsumer();
183+
await task;
184+
}
185+
186+
private sealed class TestCompletionSource : ValueTaskCompletionSource
187+
{
188+
public new bool TrySetResult(object completionData, short? completionToken, Exception e, out bool resumable)
189+
=> base.TrySetResult(completionData, completionToken, e, out resumable);
190+
191+
public new object CompletionData => base.CompletionData;
192+
193+
public new void NotifyConsumer() => base.NotifyConsumer();
194+
}
170195
}

src/DotNext.Threading/Threading/AsyncAutoResetEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public bool Set()
9393
}
9494
}
9595

96-
suspendedCaller?.Resume();
96+
suspendedCaller?.NotifyConsumer();
9797
}
9898

9999
return result;

src/DotNext.Threading/Threading/AsyncCorrelationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public bool Pulse(TKey eventId, in Result<TValue> value, out object? userData)
7777
userData = node.UserData;
7878
result = node.TrySetResult(Sentinel.Instance, completionToken, in value, out var resumable);
7979
if (resumable)
80-
node.Resume();
80+
node.NotifyConsumer();
8181
}
8282
else
8383
{

src/DotNext.Threading/Threading/AsyncExchanger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public ValueTask<T> ExchangeAsync(T value, TimeSpan timeout, CancellationToken t
172172
break;
173173

174174
resume_callers:
175-
suspendedCaller?.Resume();
175+
suspendedCaller?.NotifyConsumer();
176176
break;
177177

178178
create_task:
@@ -236,7 +236,7 @@ public bool TryExchange(ref T value)
236236
}
237237
}
238238

239-
suspendedCaller?.Resume();
239+
suspendedCaller?.NotifyConsumer();
240240
return result;
241241
}
242242

src/DotNext.Threading/Threading/AsyncExclusiveLock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void Release()
226226
}
227227
}
228228

229-
suspendedCaller?.Resume();
229+
suspendedCaller?.NotifyConsumer();
230230
}
231231

232232
private protected sealed override bool IsReadyToDispose => manager is { Value: false } && IsEmptyQueue;

src/DotNext.Threading/Threading/Tasks/LinkedValueTaskCompletionSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal void Unwind()
4545
for (LinkedValueTaskCompletionSource<T>? current = this, next; current is not null; current = next)
4646
{
4747
next = current.CleanupAndGotoNext();
48-
current.Resume();
48+
current.NotifyConsumer();
4949
}
5050
}
5151

src/DotNext.Threading/Threading/Tasks/ManualResetCompletionSource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void CancellationRequested(object? expectedVersion, CancellationToken to
5858
Debug.Assert(versionAndStatus.Status is ManualResetCompletionSourceStatus.WaitForConsumption);
5959
}
6060

61-
Resume();
61+
NotifyConsumer();
6262

6363
exit:
6464
return;
@@ -150,7 +150,7 @@ protected object? CompletionData
150150
/// <summary>
151151
/// Invokes continuation callback and cleanup state of this source.
152152
/// </summary>
153-
protected internal void Resume()
153+
protected internal void NotifyConsumer()
154154
{
155155
state.Detach().Dispose();
156156

@@ -166,8 +166,8 @@ protected internal void Resume()
166166
/// </summary>
167167
/// <param name="completionData">Custom data to be record to <see cref="CompletionData"/> property.</param>
168168
/// <returns>
169-
/// <see langword="true"/> if the immediate caller must call <see cref="Resume"/> to execute the callback;
170-
/// <see langword="false"/> to ignore invocation of <see cref="Resume"/> method because the callback
169+
/// <see langword="true"/> if the immediate caller must call <see cref="NotifyConsumer"/> to execute the callback;
170+
/// <see langword="false"/> to ignore invocation of <see cref="NotifyConsumer"/> method because the callback
171171
/// is not provided.
172172
/// </returns>
173173
private protected bool SetResult(object? completionData)

src/DotNext.Threading/Threading/Tasks/TaskCompletionPipe.Queue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private void EnqueueCompletedTask(LinkedTaskNode node, uint expectedVersion)
122122
: null;
123123
}
124124

125-
suspendedCaller?.Resume();
125+
suspendedCaller?.NotifyConsumer();
126126
}
127127

128128
private bool TryDequeueCompletedTask([NotNullWhen(true)] out T? task, out object? userData)

src/DotNext.Threading/Threading/Tasks/TaskCompletionPipe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private bool TryAdd(T task, out uint currentVersion, object? userData)
119119
}
120120

121121
// decouple producer thread from consumer thread
122-
suspendedCaller?.Resume();
122+
suspendedCaller?.NotifyConsumer();
123123
return result;
124124
}
125125

src/DotNext.Threading/Threading/Tasks/ValueTaskCompletionSource.T.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private bool TrySetResult(object? completionData, short? completionToken, in Res
9696
var completed = TrySetResult(completionData, completionToken, in result, out var resumable);
9797
if (resumable)
9898
{
99-
Resume();
99+
NotifyConsumer();
100100
}
101101

102102
return completed;
@@ -117,7 +117,7 @@ private bool SetResult(in Result<T> result, object? completionData = null)
117117
/// <param name="completionToken">The optional completion token.</param>
118118
/// <param name="result">The result to be stored as the result of <see cref="ValueTask{TResult}"/>.</param>
119119
/// <param name="resumable">
120-
/// <see langword="true"/> if <see cref="ManualResetCompletionSource.Resume()"/> needs to be called to resume
120+
/// <see langword="true"/> if <see cref="ManualResetCompletionSource.NotifyConsumer"/> needs to be called to resume
121121
/// the consumer of <see cref="ValueTask{TResult}"/>.
122122
/// </param>
123123
/// <returns>

0 commit comments

Comments
 (0)