Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.SetResult(TValue) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
19
Source : BatchThunderingHerdProtection.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
static void SetAllCompletionSources(TaskCompletionSource<TValue>[] taskCompletionSources, TValue[] loaded)
{
int j = 0;
foreach (var tcs in taskCompletionSources)
{
var value = loaded[j];
var ignored = Task.Run(() => tcs.SetResult(value));
j++;
}
}
19
Source : ThunderingHerdProtection.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public async Task<TValue> GetAsync(TKey key)
{
TaskCompletionSource<TValue> tcs;
bool alreadyLoading;
lock (_inProgress)
{
alreadyLoading = _inProgress.TryGetOrAdd(key, NewTcs, out tcs);
}
if (alreadyLoading)
{
return await tcs.Task;
}
// call the data source to load it
var value = await _dataSource.GetAsync(key);
var ignored = Task.Run(() => tcs.SetResult(value));
lock (_inProgress)
{
_inProgress.Remove(key);
}
return value;
}
19
Source : DataLoaderBase.cs
with MIT License
from ChilliCream
with MIT License
from ChilliCream
private static void SetSingleResult(
TaskCompletionSource<TValue> promise,
TKey key,
Result<TValue> result)
{
if (result.IsError)
{
DiagnosticEvents.ReceivedError(key, result);
promise.SetException(result);
}
else
{
promise.SetResult(result);
}
}
19
Source : DataLoaderBase.cs
with MIT License
from ChilliCream
with MIT License
from ChilliCream
private void SetSingleResult(
TaskCompletionSource<TValue> promise,
TKey key,
Result<TValue> result)
{
if (result.Kind is ResultKind.Value)
{
promise.SetResult(result);
}
else
{
_diagnosticEvents.BatchItemError(key, result.Error!);
promise.SetException(result.Error!);
}
}