Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.SetResult(QueryResult) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : FakeConsulClient.cs
with MIT License
from andyalm
with MIT License
from andyalm
public async Task CompleteGetAsync(string key, QueryResult<KVPair> result)
{
if (_getCalls.TryGetValue(key, out var completionSource))
{
_getCalls.Remove(key);
completionSource.SetResult(result);
await completionSource.Task;
}
else
{
var serviceCallResetEvent = new AsyncAutoResetEvent(false);
_waitingGetCalls[key] = serviceCallResetEvent;
if (!(await serviceCallResetEvent.WaitAsync(500)))
{
throw new InvalidOperationException($"Timed out waiting for a request for key '{key}' to be initiated");
}
}
}
19
Source : FakeConsulClient.cs
with MIT License
from andyalm
with MIT License
from andyalm
public async Task CompleteServiceAsync(string serviceName, QueryResult<CatalogService[]> result)
{
if (_serviceCalls.TryGetValue(serviceName, out var completionSource))
{
_serviceCalls.Remove(serviceName);
completionSource.SetResult(result);
await completionSource.Task;
}
else
{
var serviceCallResetEvent = new AsyncAutoResetEvent(false);
_waitingServiceCalls[serviceName] = serviceCallResetEvent;
if (!(await serviceCallResetEvent.WaitAsync(500)))
{
throw new InvalidOperationException($"Timed out waiting for a request for service requst '{serviceName}' to be initiated");
}
}
}
19
Source : FakeConsulClient.cs
with MIT License
from andyalm
with MIT License
from andyalm
public async Task CompleteListAsync(string prefix, QueryResult<KVPair[]> result)
{
if (_listCalls.TryGetValue(prefix, out var completionSource))
{
_listCalls.Remove(prefix);
completionSource.SetResult(result);
await completionSource.Task;
}
else
{
var serviceCallResetEvent = new AsyncAutoResetEvent(false);
_waitingGetCalls[prefix] = serviceCallResetEvent;
if (!(await serviceCallResetEvent.WaitAsync(500)))
{
throw new InvalidOperationException($"Timed out waiting for a request for key prefix '{prefix}' to be initiated");
}
}
}