diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs index e87721f..ba3bd22 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs @@ -9,6 +9,7 @@ namespace Cysharp.Threading.Tasks public static class CancellationTokenExtensions { static readonly Action cancellationTokenCallback = Callback; + static readonly Action 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 diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 97a33cc..97fb801 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -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(); + // 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();