public static IUniTaskSource <AssetBundle> Create(AssetBundleCreateRequest asyncOperation, CancellationToken cancellationToken, out short token) { if (cancellationToken.IsCancellationRequested) { return(AutoResetUniTaskCompletionSource <AssetBundle> .CreateFromCanceled(cancellationToken, out token)); } if (!pool.TryPop(out var result)) { result = new AssetBundleCreateRequestWithCancellationSource(); } result.asyncOperation = asyncOperation; result.cancellationToken = cancellationToken; result.completed = false; TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, result); asyncOperation.completed += result.continuationAction; token = result.core.Version; return(result); }
public static UniTask <AssetBundle> WithCancellation(this AssetBundleCreateRequest asyncOperation, CancellationToken cancellationToken) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) { return(UniTask.FromCanceled <AssetBundle>(cancellationToken)); } if (asyncOperation.isDone) { return(UniTask.FromResult(asyncOperation.assetBundle)); } return(new UniTask <AssetBundle>(AssetBundleCreateRequestWithCancellationSource.Create(asyncOperation, cancellationToken, out var token), token)); }