Aetheria/Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Utils/CancellableTask.cs
hyperion51 e96146b7bb Out with MagicOnion, in with LiteNetLib
Removed MagicOnion
Added LiteNetLib
Created client and server abstractions
Fixed serialization bugs
2020-03-24 14:36:22 +00:00

38 lines
No EOL
1.1 KiB
C#

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System;
using System.Threading;
using System.Threading.Tasks;
using RethinkDb.Driver.Net;
namespace RethinkDb.Driver.Utils
{
public class CancellableTask : TaskCompletionSource<Response>, IDisposable
{
private readonly CancellationToken cancelToken;
private CancellationTokenRegistration registration;
public CancellableTask(CancellationToken cancelToken)
{
this.cancelToken = cancelToken;
this.registration = this.cancelToken.Register(OnCancellation, false);
}
private void OnCancellation()
{
this.TrySetCanceled();
//if the user successfully signaled they want to
//cancel, remove the registration because
//the task status = canceled has been set.
//don't need the registration any more.
this.Dispose();
}
public void Dispose()
{
this.registration.Dispose();
}
}
}