public void AllPromiseIsCancelededWhenAnyPromiseIsAlreadyCanceled() { int cancelations = 0; string cancelation = "Cancel!"; var deferred = Promise.NewDeferred <int>(); var promise = Promise.Canceled <int, string>(cancelation); promise.Retain(); Promise.Manager.HandleCompletes(); Promise.All(deferred.Promise, promise) .Then(v => Assert.Fail("Promise was resolved when it should have been canceled.")) .CatchCancelation(ex => { Assert.AreEqual(cancelation, ex.Value); ++cancelations; }); Promise.All((Promise)deferred.Promise, promise) .Then(() => Assert.Fail("Promise was resolved when it should have been canceled.")) .CatchCancelation(ex => { Assert.AreEqual(cancelation, ex.Value); ++cancelations; }); deferred.Resolve(0); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, cancelations); promise.Release(); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, cancelations); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public void AllPromiseIsRejectedWhenAnyPromiseIsAlreadyRejected() { int rejected = 0; string rejection = "Error!"; var deferred = Promise.NewDeferred <int>(); var promise = Promise.Rejected <int, string>(rejection); promise.Retain(); Promise.Manager.HandleCompletes(); Promise.All(deferred.Promise, promise) .Then(v => Assert.Fail("Promise was resolved when it should have been rejected.")) .Catch <string>(ex => { Assert.AreEqual(rejection, ex); ++rejected; }); Promise.All((Promise)deferred.Promise, promise) .Then(() => Assert.Fail("Promise was resolved when it should have been rejected.")) .Catch <string>(ex => { Assert.AreEqual(rejection, ex); ++rejected; }); deferred.Resolve(0); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, rejected); promise.Release(); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, rejected); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public Promise <MockScene> Navigate(string sceneName) { Debug.Log(string.Format("NavController.Navigate - init navigation ; sceneName={0}", sceneName)); var controller = _locator.Locate(sceneName); Debug.Log(string.Format("NavController.Navigate - controller located ; controller.FriendlyName={0} ; controllerType={1}", controller.FriendlyName, controller.GetType())); var switchingControllerPromise = ChangeCurrentController(controller) .Then(x => { Debug.Log(string.Format("NavController.Navigate - [Then] ChangeCurrentController complete. result.x={0}", x)); return("lawl"); }) .Then(x => { Debug.Log(string.Format("NavController.Navigate - [Then] ChangeCurrentController complete. result.x={0}", x)); }); var sceneLoad = _loader.Load(sceneName) .Then(x => { Debug.Log(string.Format("NavController.Navigate - [Then] load complete. result.x={0}", x)); //return "daIssue";//NOTE: This will cause an error, but for now its for testing purposes }) .Then(x => { Debug.Log(string.Format("NavController.Navigate - [Thenx2] load complete. result.x={0}", x)); //throw new ArgumentException("Oqqqowww! :/"); }) .Fail <ArgumentException>(x => Debug.Log(string.Format("NavController.Navigate - [Fail<ArgumentException>] _loader.Load ERRORR! x={0}", x))); //.Fail<System.Net.HttpStatusCode>(x => Debug.Log(string.Format("NavController.Navigate - [Fail<HttpStatusCode>] _loader.Load ERRORR! x={0}", x))) //.Done(x => Debug.Log(string.Format("NavController.Navigate - [Done] x={0}", x))); return(Promise.All(switchingControllerPromise, sceneLoad) .Then(x => { Debug.Log(string.Format("NavController.Navigate - All [Then] all complete. result. x[0]={0} x[1]={1}", x)); return (MockScene)x[1]; // return second value which is sceneLoad result. }) .Progress <int>(x => Debug.Log(string.Format("NavController.Navigate - All [Progress]. result. x={0}", x)))); }
public void AllProgressIsNoLongerReportedFromCanceled1() { var deferred1 = Promise.NewDeferred <int>(); var cancelationSource = CancelationSource.New(); var deferred2 = Promise.NewDeferred <int>(cancelationSource.Token); var deferred3 = Promise.NewDeferred <int>(); float progress = float.NaN; Promise.All(deferred1.Promise, deferred2.Promise, deferred3.Promise) .Progress(p => progress = p); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0f / 3f, progress, TestHelper.progressEpsilon); deferred1.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0.5f / 3f, progress, TestHelper.progressEpsilon); deferred1.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1f / 3f, progress, TestHelper.progressEpsilon); deferred2.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); cancelationSource.Cancel(); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); deferred3.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); deferred3.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); cancelationSource.Dispose(); TestHelper.Cleanup(); }
public IPromise EnterAnimation() { return(Promise.All( new Promise((resolve, reject) => { Vector2 targetPosition = this.closeGame.GetComponentInChildren <WaypointUi>().GetPosition(); RectTransform rectTransform = this.closeGame.GetComponent <RectTransform>(); rectTransform.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), new Promise((resolve, reject) => { Vector2 targetPosition = this.openLeaderboard.GetComponentInChildren <WaypointUi>().GetPosition(); RectTransform rectTransform = this.openLeaderboard.GetComponent <RectTransform>(); rectTransform.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), this.levelSelector.EnterAnimation() )); }
public void combined_promise_is_rejected_when_both_promises_are_rejected() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); TestHelpers.VerifyDoesntThrowUnhandledException(() => { var all = Promise <int> .All(EnumerableExt.FromItems <IPromise <int> >(promise1, promise2)); all.Then(v => throw new Exception("Shouldn't happen")); var errors = 0; all.Catch(e => { ++errors; }); promise1.Reject(new Exception("Error!")); promise2.Reject(new Exception("Error!")); Assert.Equal(1, errors); }); }
public ResourceRef[] addResources(string[] urls, int[] priorities, bool bAsync, Action <ResourceRef[]> actComplate, Action <Exception> actError) { IPromise <ResourceRef>[] promises = new IPromise <ResourceRef> [urls.Length]; ResourceRef[] refs = new ResourceRef[urls.Length]; for (int i = 0; i < urls.Length; i++) { int priority = (priorities != null)?(priorities.Length >= urls.Length?priorities[i]:priorities[0]):0; promises[i] = _addResource(urls[i], priority, bAsync); refs[i] = getResource(urls[i]); } Func <IEnumerable <ResourceRef>, IEnumerable <IPromise <ResourceRef> > > funcResolved = resources => { actComplate(resources.ToArray()); return(promises); }; Promise <ResourceRef> .All(promises).Catch(actError).ThenAll(funcResolved).Done(); return(refs); }
public void AllProgressIsNoLongerReportedFromRejected1() { var deferred1 = Promise.NewDeferred <int>(); var deferred2 = Promise.NewDeferred <int>(); var deferred3 = Promise.NewDeferred <int>(); float progress = float.NaN; Promise.All(deferred1.Promise, deferred2.Promise, deferred3.Promise) .Progress(p => progress = p) .Catch(() => { }); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0f / 3f, progress, TestHelper.progressEpsilon); deferred1.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0.5f / 3f, progress, TestHelper.progressEpsilon); deferred1.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1f / 3f, progress, TestHelper.progressEpsilon); deferred2.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); deferred2.Reject("Reject"); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); deferred3.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); deferred3.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 3f, progress, TestHelper.progressEpsilon); TestHelper.Cleanup(); }
public void AllPromiseIsResolvedIfThereAreNoPromises() { var completed = 0; Promise.All(Enumerable.Empty <Promise <int> >()) .Then(v => { ++completed; Assert.IsEmpty(v); }); Promise.All(Enumerable.Empty <Promise>()) .Then(() => ++ completed); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, completed); TestHelper.Cleanup(); }
public void Promise_Test() { var t = new Promise <int>((res, rej) => { rej(new Exception()); }).Then(x => 100).Catch(x => - 1).Then(x => x * 3).Task.ToSync(); Assert.Equal(t, -3); var t2 = new Promise <int>((res, rej) => { res(100); }).Catch(x => - 1).Then(x => x * 3).Task.ToSync(); Assert.Equal(t2, 300); var p = new Promise <int>((res, rej) => { Thread.Sleep(100); res(100); }); var p2 = new Promise <int>((res, rej) => { Thread.Sleep(200); res(200); }); var c = Promise <object> .All(new Promise <object>[] { (Promise <object>)p, (Promise <object>)p2 }) .Task.ToSync(); var c2 = Promise <object> .Race(new Promise <object>[] { (Promise <object>)p, (Promise <object>)p2 }) .Task.ToSync(); Assert.Equal(c2, 100); var d = new Promise <int>((res, rej) => { rej(new Exception()); }).Then(x => x * 2, x => - 1).Then(x => x * 3).Task.ToSync(); Assert.Equal(d, -3); }
public void AllProgressIsNormalized3() { var deferred1 = Promise.NewDeferred <int>(); var deferred3 = Promise.NewDeferred <int>(); var deferred4 = Promise.NewDeferred <int>(); float progress = float.NaN; Promise.All(deferred1.Promise, Promise.Resolved(1), deferred3.Promise, deferred4.Promise) .Progress(p => progress = p); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1f / 4f, progress, TestHelper.progressEpsilon); deferred1.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(1.5f / 4f, progress, TestHelper.progressEpsilon); deferred1.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(2f / 4f, progress, TestHelper.progressEpsilon); deferred3.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(2.5f / 4f, progress, TestHelper.progressEpsilon); deferred3.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(3f / 4f, progress, TestHelper.progressEpsilon); deferred4.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(3.5f / 4f, progress, TestHelper.progressEpsilon); deferred4.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(4f / 4f, progress, TestHelper.progressEpsilon); TestHelper.Cleanup(); }
public void combined_promise_is_resolved_when_all_promises_are_already_resolved() { var promise1 = Promise <int> .Resolved(1); var promise2 = Promise <int> .Resolved(1); TestHelpers.VerifyDoesntThrowUnhandledException(() => { var all = Promise <int> .All(EnumerableExt.FromItems(promise1, promise2)); var completed = 0; all.Then(v => { ++completed; Assert.Empty(v); }); Assert.Equal(1, completed); }); }
public void combined_promise_is_resolved_when_children_are_resolved() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); var all = Promise.All(new Promise <int>[] { promise1, promise2 }); var completed = 0; all.Then(results => { ++completed; Assert.Equal(2, results.Length); Assert.Equal(1, results[0]); Assert.Equal(2, results[1]); }); promise1.Resolve(1); promise2.Resolve(2); Assert.Equal(1, completed); }
public void combined_promise_is_rejected_when_both_promises_are_rejected() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); var all = Promise.All(new Promise <int>[] { promise1, promise2 }); all.Then(v => { throw new ApplicationException("Shouldn't happen"); }); var errors = 0; all.Catch(e => { ++errors; }); promise1.Reject(new ApplicationException("Error!")); promise2.Reject(new ApplicationException("Error!")); Assert.Equal(1, errors); }
private Promise ChangeCurrentController(ISceneController sceneController) { if (_currentSceneController == null) { Debug.Log(string.Format("NavController.ChangeCurrentController - SceneController={0}", sceneController)); return(sceneController.Init() .Then(x => { Debug.Log(string.Format("NavController.ChangeCurrentController - Init [Then] - Controller changed. sceneController={0}", sceneController)); _currentSceneController = sceneController; })); } return(Promise.All(_currentSceneController.Shutdown(), sceneController.Init()) .Then(x => { Debug.Log(string.Format("NavController.ChangeCurrentController - All [Then] - Controller changed. sceneController={0}", sceneController)); _currentSceneController = sceneController; return x; }) .Progress <string>(x => Debug.Log(string.Format("The progress status={0}", x)))); }
private void InitializeApi(LoginApi api) { api.Login(string.Empty, string.Empty).Then(loginResult => { if (loginResult) { Promise.All( Database.Init().Then(DatabaseApiInitialized), NetworkBroadcast.Init().Then(NetworkBroadcastApiInitialized), History.Init().Then(HistoryApiInitialized), Registration.Init().Then(RegistrationApiInitialized) ).Then(InitializeDone).Catch(ex => { CustomTools.Console.DebugError("EchoApiManager class", CustomTools.Console.LogRedColor(ex.Message), "Initialize all api"); }); } else { CustomTools.Console.DebugLog("EchoApiManager class", CustomTools.Console.LogRedColor("Login Failed!"), "Login()"); } }); }
public void AllPromiseIsResolvedWhenAllPromisesAreResolved() { var deferred1 = Promise.NewDeferred <int>(); var deferred2 = Promise.NewDeferred <int>(); var completed = 0; Promise.All(deferred1.Promise, deferred2.Promise) .Then(values => { ++completed; Assert.AreEqual(2, values.Count); Assert.AreEqual(1, values[0]); Assert.AreEqual(2, values[1]); }); Promise.All((Promise)deferred1.Promise, deferred2.Promise) .Then(() => ++ completed); Promise.Manager.HandleCompletes(); Assert.AreEqual(0, completed); deferred1.Resolve(1); Promise.Manager.HandleCompletes(); Assert.AreEqual(0, completed); deferred2.Resolve(2); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, completed); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
private Menu MenuProcess() { this.ui.MakeNonInteractable(); Promise.All( this.fadeTransition.Enter(), this.ui.EnterAnimation() ) .Then(() => { this.ui.MakeInteractable(); return(this.ui.WaitForNextLevel()); }) .Then((world) => { this.ui.MakeNonInteractable(); this.dataController.SetCurrentWorldName(world); this.fadeTransition.SetColor(Color.white); return(Promise.All( this.ui.ZoomIn(1.5f), this.fadeTransition.Exit(1.5f) )); }) .Then(() => Messenger.Publish(new ChangeSceneMessage(SRScenes.Game))); return(this); }
private void Update() { if (Input.GetKeyDown(KeyCode.Space) || InputExtensions.GetTouchDown()) { List <IPromise> reels = new List <IPromise>(); for (int i = 0; i < reelDisplays.Count; ++i) { symbolStreams[i].Reset(); reels.Add(reelDisplays[i].Spin(symbolStreams[i])); } Promise.All(reels).Done(ReelSpinComplete); } if (Input.GetKeyDown(KeyCode.S)) { foreach (var stream in symbolStreams) { stream.Splice(targetStop); } targetStop++; } }
public void all_with_rejected_promise() { bool resolved = false; bool rejected = false; Exception caughtException = null; Exception exception = new Exception(); var promiseA = new Promise(); var promise = Promise .All(promiseA, Promise.Rejected(exception)) .Then(() => resolved = true) .Catch(ex => { caughtException = ex; rejected = true; }); promiseA.Resolve(); Assert.Equal(false, resolved); Assert.Equal(true, rejected); Assert.Equal(exception, caughtException); }
//most complicated logic we have. Need to loop over the routing objects and handle //objects coming in the stream in order //therefore we construct a series of promises public IPromise <ProtoMessage> RouteMessage(ProtoMessage protoMessage) { var allPromises = new List <Promise <ProtoMessage> >(); // we're going to loop over each message sent // and for each handler of those objects // processing each partial response in order // and sending back the full response in the end Debug.Log($"Objects to route: {protoMessage.ProtoObjectList.Count}"); foreach (var msgTuple in protoMessage.ProtoObjectList) { var objIx = msgTuple.Item1.ProtoType; var objHandlers = this.handlers[objIx]; Debug.Log($"Obj Type {objIx}, handler count {objHandlers.Count}"); foreach (var methodAndObj in objHandlers) { var methodToCall = methodAndObj.Item1; var objToCall = methodAndObj.Item2; Debug.Log($"Promising to send the object to {objToCall.GetType().Name}"); allPromises.Add((Promise <ProtoMessage>)methodToCall.Invoke(objToCall, new object[] { msgTuple.Item2 })); } } //here we guarantee to return eventually -- so this can be async handled //first fullfill all of our promises, //then take the collection of results and merge them into a single return message return(Promise <ProtoMessage> .All(allPromises) .Then(protoCollection => { Debug.Log("All messages routed and responded to"); return mergePromise(protoCollection); })); }
public IPromise EnterAnimation() { return(Promise.All( new Promise((resolve, reject) => { Vector2 targetPosition = this.goLeft.GetComponentInChildren <WaypointUi>().GetPosition(); RectTransform rectTransform = this.goLeft.GetComponent <RectTransform>(); rectTransform.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), new Promise((resolve, reject) => { Vector2 targetPosition = this.goRight.GetComponentInChildren <WaypointUi>().GetPosition(); RectTransform rectTransform = this.goRight.GetComponent <RectTransform>(); rectTransform.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), new Promise((resolve, reject) => { Vector2 targetPosition = this.worldTitle.GetComponentInChildren <WaypointUi>().GetPosition(); this.worldTitle.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), new Promise((resolve, reject) => { Vector2 targetPosition = this.highScore.GetComponentInChildren <WaypointUi>().GetPosition(); this.highScore.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }), new Promise((resolve, reject) => { Vector2 targetPosition = this.levelDoors[1].GetComponentInChildren <WaypointUi>().GetPosition(); RectTransform rectTransform = this.levelDoors[1].GetComponent <RectTransform>(); rectTransform.DOMove(targetPosition, 1f, false) .From() .OnComplete(() => resolve()); }))); }
public void AllProgressIsNormalized9() { var deferred1 = Promise.NewDeferred <int>(); var deferred2 = Promise.NewDeferred <int>(); float progress = float.NaN; Promise.All ( deferred1.Promise .Then(x => Promise.Resolved(x)), deferred2.Promise .Then(x => Promise.Resolved(x)) ) .Progress(p => progress = p); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0f / 4f, progress, 0f); deferred1.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(0.5f / 4f, progress, TestHelper.progressEpsilon); deferred1.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(2f / 4f, progress, TestHelper.progressEpsilon); deferred2.ReportProgress(0.5f); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(2.5f / 4f, progress, TestHelper.progressEpsilon); deferred2.Resolve(1); Promise.Manager.HandleCompletesAndProgress(); Assert.AreEqual(4f / 4f, progress, TestHelper.progressEpsilon); TestHelper.Cleanup(); }
public void AllPromiseIsResolvedIfThereAreNoPromises() { var completed = 0; Promise.All(Enumerable.Empty <Promise <int> >()) .Then(v => { ++completed; Assert.IsEmpty(v); }); Promise.All(Enumerable.Empty <Promise>()) .Then(() => ++ completed); Promise.Manager.HandleCompletes(); Assert.AreEqual(2, completed); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public IPromise animateToItem( int itemIndex, TimeSpan duration, Curve curve ) { if (!this.hasClients) { return(Promise.Resolved()); } List <IPromise> futures = new List <IPromise>(); foreach (_FixedExtentScrollPosition position in this.positions) { futures.Add(position.animateTo( itemIndex * position.itemExtent, duration: duration, curve: curve )); } return(Promise.All(futures)); }
public IPromise Show(int timeValue, int healthValue, int scoreValue) { ResetValues(); this.background.GetComponent <Image>().enabled = true; this.continueButton.gameObject.SetActive(true); this.time.SetActive(true); this.health.SetActive(true); this.score.SetActive(true); this.continueButton.interactable = false; TweenEaseAnimationScaleComponent.CreateSequence("WinWorld", new GameObject[] { this.continueButton.gameObject, this.background }, () => this.continueButton.interactable = true); return(Promise.All(new Promise((resolve, rejected) => { StartCoroutine(ScoreUpAnimation(this.time.GetComponent <Text>(), timeValue, () => resolve()));; }), new Promise((resolve, rejected) => { StartCoroutine(ScoreUpAnimation(this.health.GetComponent <Text>(), healthValue, () => resolve())); }), new Promise((resolve, rejected) => { StartCoroutine(ScoreUpAnimation(this.score.GetComponent <Text>(), scoreValue, () => resolve())); }), new Promise((resolve, reject) => { UnityAction onClick = null; onClick = () => { SoundData playRestart = new SoundData(GetInstanceID(), SRResources.Audio.Effects.Confirm); Messenger.Publish(new PlayEffectMessage(playRestart)); this.continueButton.onClick.RemoveListener(onClick); resolve(); }; this.continueButton.onClick.AddListener(onClick); }) )); }
public void combined_promise_is_rejected_when_both_promises_are_rejected() { var promise1 = new Promise(); var promise2 = new Promise(); var all = Promise.All(EnumerableExt.FromItems <IPromise>(promise1, promise2)); all.Then(() => { throw new ApplicationException("Shouldn't happen"); }); var errors = 0; all.Catch(e => { ++errors; }); promise1.Reject(new ApplicationException("Error!")); promise2.Reject(new ApplicationException("Error!")); Assert.Equal(1, errors); }
public static IPromise ensureVisible(BuildContext context, float alignment = 0.0f, TimeSpan?duration = null, Curve curve = null ) { duration = duration ?? TimeSpan.Zero; curve = curve ?? Curves.ease; List <IPromise> futures = new List <IPromise>(); ScrollableState scrollable = of(context); while (scrollable != null) { futures.Add(scrollable.position.ensureVisible( context.findRenderObject(), alignment: alignment, duration: duration, curve: curve )); context = scrollable.context; scrollable = of(context); } if (futures.isEmpty() || duration == TimeSpan.Zero) { return(Promise.Resolved()); } if (futures.Count == 1) { return(futures.Single()); } return(Promise.All(futures)); }
public void combined_promise_is_rejected_when_second_promise_is_rejected() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); var all = Promise <int> .All(LinqExts.FromItems <IPromise <int> >(promise1, promise2)); all.Then(v => { throw new ApplicationException("Shouldn't happen"); }); var errors = 0; all.Catch(e => { ++errors; }); promise1.Resolve(2); promise2.Reject(new ApplicationException("Error!")); Assert.Equal(1, errors); }
public void combined_promise_is_resolved_when_children_are_resolved() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); var all = Promise <int> .All(LinqExts.FromItems <IPromise <int> >(promise1, promise2)); var completed = 0; all.Then(v => { ++completed; var values = v.ToArray(); Assert.Equal(2, values.Length); Assert.Equal(1, values[0]); Assert.Equal(2, values[1]); }); promise1.Resolve(1); promise2.Resolve(2); Assert.Equal(1, completed); }