mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-22 15:50:10 +00:00
Add IDisposable.AddTo(cancellationToken)
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
public static class CancellationTokenExtensions
|
public static class CancellationTokenExtensions
|
||||||
{
|
{
|
||||||
static readonly Action<object> cancellationTokenCallback = Callback;
|
static readonly Action<object> cancellationTokenCallback = Callback;
|
||||||
|
static readonly Action<object> disposeCallback = DisposeCallback;
|
||||||
|
|
||||||
public static (UniTask, CancellationTokenRegistration) ToUniTask(this CancellationToken cancellationToken)
|
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
|
public struct CancellationTokenAwaitable
|
||||||
|
|||||||
@@ -429,7 +429,9 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
PlayerLoopInfo.Inject();
|
UnityEngine.Debug.Log("Start:" + PlayerLoopInfo.CurrentLoopType);
|
||||||
|
|
||||||
|
//PlayerLoopInfo.Inject();
|
||||||
|
|
||||||
//_ = AsyncFixedUpdate();
|
//_ = AsyncFixedUpdate();
|
||||||
//StartCoroutine(CoroutineFixedUpdate());
|
//StartCoroutine(CoroutineFixedUpdate());
|
||||||
@@ -438,8 +440,11 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
// Application.logMessageReceived += Application_logMessageReceived;
|
// 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; }
|
public static Type CurrentLoopType { get; private set; }
|
||||||
|
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||||
public static void Inject()
|
public static void Inject()
|
||||||
{
|
{
|
||||||
var system = PlayerLoop.GetCurrentPlayerLoop();
|
var system = PlayerLoop.GetCurrentPlayerLoop();
|
||||||
|
|||||||
Reference in New Issue
Block a user