コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: malliina/musicpimp-win
        public async Task TaskTests()
        {
            Debug.WriteLine("Testing tasks...");
            var winner = await AsyncTasks.FirstSuccessfulWithin(BuildTasks(), TimeSpan.FromMilliseconds(2000));

            Assert.AreEqual("done sleeping", winner);
            try {
                string noWinners = await AsyncTasks.FirstSuccessfulWithin(BuildTasks(), TimeSpan.FromMilliseconds(200));

                Debug.WriteLine(noWinners);
                Assert.Fail("Expected timeout, got success.");
            } catch (TimeoutException) {
            }
            try {
                var noWinners = await AsyncTasks.FirstSuccessfulWithin(BuildTasks().Skip(2).ToList(), TimeSpan.FromMilliseconds(5000));

                Assert.Fail("Expected failure, got success.");
            } catch (NoResultsException) {
            }
        }
コード例 #2
0
        private Task <T> TestIPs <T>(IEnumerable <string> ips, Func <string, Func <CancellationToken, Task <T> > > test)
        {
            var tests = ips.Select(test).ToList();

            return(AsyncTasks.FirstSuccessfulWithin <T>(tests, TimeSpan.FromSeconds(8)));
        }