Пример #1
0
        public async Task Timeout()
        {
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateAsync(999);
                var(hasValue, value) = await ValueTaskEx.WhenAny(vtask, delay);

                hasValue.Should().BeTrue();
                value.Should().Be(999);
            }
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateAsyncSlow(999);
                var(hasValue, value) = await ValueTaskEx.WhenAny(vtask, delay);

                hasValue.Should().BeFalse();
            }
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateSync(999);
                var(hasValue, value) = await ValueTaskEx.WhenAny(vtask, delay);

                hasValue.Should().BeTrue();
                value.Should().Be(999);
            }
        }
Пример #2
0
        public async Task Array()
        {
            var a      = CreateSync();
            var b      = CreateAsync();
            var c      = CreateAsyncSlow();
            var result = await ValueTaskEx.WhenAny(new[] { a, b, c });

            result.Should().Be(0);
        }
Пример #3
0
        public async Task WithAsync()
        {
            var a      = CreateAsync();
            var b      = CreateSync();
            var c      = CreateAsyncSlow();
            var result = await ValueTaskEx.WhenAny(a, b, c);

            result.Should().Be(1);
        }
Пример #4
0
        public async Task AnySync()
        {
            var a      = CreateSync();
            var b      = CreateSync();
            var c      = CreateSync();
            var result = await ValueTaskEx.WhenAny(a, b, c);

            result.Should().Be(0);
        }
Пример #5
0
        public async Task Array()
        {
            var a      = CreateSync(1);
            var b      = CreateAsync(2);
            var c      = CreateAsync(3);
            var result = await ValueTaskEx.WhenAny(new[] { a, b, c });

            result.winArgumentIndex.Should().Be(0);
            result.result.Should().Be(1);
        }
Пример #6
0
        public async Task WithAsync()
        {
            var a      = CreateAsync(1);
            var b      = CreateSync(2);
            var c      = CreateAsync(3);
            var result = await ValueTaskEx.WhenAny(a, b, c);

            result.winArgumentIndex.Should().Be(1);

            result.result1.Should().Be(2);
        }
Пример #7
0
        public async Task Timeout()
        {
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateAsync();
                var index = await ValueTaskEx.WhenAny(vtask, delay);

                index.Should().Be(0);
            }
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateAsyncSlow();
                var index = await ValueTaskEx.WhenAny(vtask, delay);

                index.Should().Be(1);
            }
            {
                var delay = Task.Delay(TimeSpan.FromMilliseconds(100));
                var vtask = CreateSync();
                var index = await ValueTaskEx.WhenAny(vtask, delay);

                index.Should().Be(0);
            }
        }