public static IUniTaskSource <T> Create(AsyncReactiveProperty <T> parent, CancellationToken cancellationToken, out short token) { if (cancellationToken.IsCancellationRequested) { return(AutoResetUniTaskCompletionSource <T> .CreateFromCanceled(cancellationToken, out token)); } if (!pool.TryPop(out var result)) { result = new WaitAsyncSource(); } result.parent = parent; result.cancellationToken = cancellationToken; if (cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, result); } result.parent.triggerEvent.Add(result); TaskTracker.TrackActiveTask(result, 3); token = result.core.Version; return(result); }
public UniTask <T> WaitAsync(CancellationToken cancellationToken = default) { return(new UniTask <T>(WaitAsyncSource.Create(this, cancellationToken, out var token), token)); }