예제 #1
0
		protected void TrySetResult<T>(ReusablePromise<T> promise, AsyncTriggerPromiseDictionary<T> promises, T value) {
			if (promise != null) {
				promise.TrySetResult(value);
			}

			if (promises != null) {
				PromiseHelper.TrySetResultAll(promises.Values, value);
			}
		}
예제 #2
0
        protected UniTask <T> GetOrAddPromise <T>(ref AsyncTriggerPromise <T> promise, ref AsyncTriggerPromiseDictionary <T> promises, CancellationToken cancellationToken)
        {
            if (destroyCalled)
            {
                return(UniTask.FromCanceled <T>());
            }

            if (!cancellationToken.CanBeCanceled)
            {
                if (promise == null)
                {
                    promise = new AsyncTriggerPromise <T>();
                    if (!calledAwake)
                    {
                        PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
                    }
                }

                return(promise.Task);
            }

            if (promises == null)
            {
                promises = new AsyncTriggerPromiseDictionary <T>();
            }

            if (promises.TryGetValue(cancellationToken, out var cancellablePromise))
            {
                return(cancellablePromise.Task);
            }

            cancellablePromise = new AsyncTriggerPromise <T>();
            promises.Add(cancellationToken, cancellablePromise);
            if (!calledAwake)
            {
                PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
            }

            var registrationToken =
                cancellationToken.RegisterWithoutCaptureExecutionContext(Callback,
                                                                         Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise));

            if (registeredCancellations == null)
            {
                registeredCancellations = ArrayPool <CancellationTokenRegistration> .Shared.Rent(4);
            }
            ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool <CancellationTokenRegistration> .Shared);
            registeredCancellations[registeredCancellationsCount++] = registrationToken;

            return(cancellablePromise.Task);
        }
예제 #3
0
 protected void TrySetResult <T>(ReusablePromise <T> promise, AsyncTriggerPromiseDictionary <T> promises, T value)
 {
     if (promise != null)
     {
         promise.TrySetResult(value);
     }
     if (promises != null)
     {
         foreach (var item in promises.Values)
         {
             item.TrySetResult(value);
         }
     }
 }