Пример #1
0
 private void EnsureHasTask()
 {
     if (!_source.HasTask)
     {
         _source = PooledValueTaskSource <T> .Create();
     }
 }
Пример #2
0
        public void ReadSync()
        {
            var source = PooledValueTaskSource <int> .Create();

            _ = Delayed();
            Assert.Equal(42, source.Task.Result);

            async FireAndForget Delayed()
            {
                await Task.Delay(100);

                source.TrySetResult(42);
            }
        }
Пример #3
0
        public async Task CreateAndSetAsync()
        {
            var source = PooledValueTaskSource <int> .Create();

            var task = source.Task;

            Assert.False(task.IsCompleted);
            Assert.True(source.IsValid);

            Assert.True(source.TrySetResult(42));

            Assert.True(task.IsCompleted);
            Assert.Equal(42, await task);

            // now it has been fetched, it should have been reset/recycled
            Assert.False(source.IsValid);
            Assert.False(source.TrySetResult(43));
            await Assert.ThrowsAsync <InvalidOperationException>(async() => _ = await task);
        }