public void TaskFromPromiseWithResultIndexWorksWhenPromiseCompletes() { var promise = CreatePromise(); var tasks = new Task<int>[] { Task.FromPromise<int>(promise, 0), Task.FromPromise<int>(promise, 1), Task.FromPromise<int>(promise, 2), Task.FromPromise<int>(promise, -3), Task.FromPromise<int>(promise, -2), Task.FromPromise<int>(promise, -1), }; var continuationsRun = new bool[6]; Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.Running), "Tasks should be running after being created"); tasks.ForEach((x, i, _) => x.ContinueWith(t => { Assert.IsTrue(t == x, "ContinueWith parameter should be correct"); continuationsRun[i] = true; })); Window.SetTimeout(() => { Assert.IsFalse(continuationsRun.Some(x => x), "Continuations should not be run too early."); Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.Running), "Tasks should be running before promise is completed."); promise.Resolve(10, 42, 38); }, 100); Window.SetTimeout(() => { Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.RanToCompletion), "Task should be completed after promise"); Assert.IsTrue(continuationsRun.Every(x => x), "Continuations should have been run after promise was completed."); Assert.AreEqual(tasks[0].Result, 10, "Task 0 result should be correct"); Assert.AreEqual(tasks[1].Result, 42, "Task 1 result should be correct"); Assert.AreEqual(tasks[2].Result, 38, "Task 2 result should be correct"); Assert.AreEqual(tasks[3].Result, 10, "Task 3 result should be correct"); Assert.AreEqual(tasks[4].Result, 42, "Task 4 result should be correct"); Assert.AreEqual(tasks[5].Result, 38, "Task 5 result should be correct"); QUnit.Start(); }, 200); }