mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 14:36:31 +00:00
Errors sending to UI
notifying client of AI model conversion
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class CancellationTokenExtensions
|
||||
{
|
||||
public static void WaitForCancel(this CancellationToken token, TimeSpan timeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
Task.Delay(timeout, token).Wait(token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
//Don't need to catch exception, need only return from the waiting
|
||||
}
|
||||
}
|
||||
|
||||
public static Task AsTask(this CancellationToken cancellationToken)
|
||||
{
|
||||
if (!cancellationToken.CanBeCanceled)
|
||||
return new TaskCompletionSource<bool>().Task;
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return Task.FromCanceled(cancellationToken);
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var registration = cancellationToken.Register(() => tcs.TrySetResult(true));
|
||||
tcs.Task.ContinueWith(_ => registration.Dispose(), TaskScheduler.Default);
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user