mirror of https://github.com/Cysharp/UniTask
Add IDisposable.AddTo(cancellationToken)
parent
1b553f67b0
commit
9c86cfb508
|
@ -9,6 +9,7 @@ namespace Cysharp.Threading.Tasks
|
|||
public static class CancellationTokenExtensions
|
||||
{
|
||||
static readonly Action<object> cancellationTokenCallback = Callback;
|
||||
static readonly Action<object> disposeCallback = DisposeCallback;
|
||||
|
||||
public static (UniTask, CancellationTokenRegistration) ToUniTask(this CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -75,6 +76,17 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CancellationTokenRegistration AddTo(this IDisposable disposable, CancellationToken cancellationToken)
|
||||
{
|
||||
return cancellationToken.RegisterWithoutCaptureExecutionContext(disposeCallback, disposable);
|
||||
}
|
||||
|
||||
static void DisposeCallback(object state)
|
||||
{
|
||||
var d = (IDisposable)state;
|
||||
d.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public struct CancellationTokenAwaitable
|
||||
|
|
|
@ -429,7 +429,9 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
void Start()
|
||||
{
|
||||
PlayerLoopInfo.Inject();
|
||||
UnityEngine.Debug.Log("Start:" + PlayerLoopInfo.CurrentLoopType);
|
||||
|
||||
//PlayerLoopInfo.Inject();
|
||||
|
||||
//_ = AsyncFixedUpdate();
|
||||
//StartCoroutine(CoroutineFixedUpdate());
|
||||
|
@ -438,8 +440,11 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
// Application.logMessageReceived += Application_logMessageReceived;
|
||||
|
||||
// var rp = new AsyncReactiveProperty<int>();
|
||||
|
||||
|
||||
// rp.AddTo(this.GetCancellationTokenOnDestroy());
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -969,6 +974,7 @@ public class PlayerLoopInfo
|
|||
|
||||
public static Type CurrentLoopType { get; private set; }
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
public static void Inject()
|
||||
{
|
||||
var system = PlayerLoop.GetCurrentPlayerLoop();
|
||||
|
|
Loading…
Reference in New Issue