Exemplo n.º 1
0
        public async IAsyncEnumerable <TaskResult <int> > EmitCounter(TrivialCounterTask t)
        {
            yield return(await t);

            yield return(await t);

            yield return(await new TrivialCounterSubTask(await t));
        }
Exemplo n.º 2
0
        public async Task TaskCaching_Test()
        {
            var task = new TrivialCounterTask();

            await foreach (var i in  EmitCounter(task))
            {
                ;
            }
            Assert.Equal(1, task.Counter);
        }
Exemplo n.º 3
0
        public async Task TaskCaching_Test()
        {
            var task = new TrivialCounterTask();

            await foreach (var i in EmitCounter(task))
            {
                ;
            }
            // No matter how many times task is awaited, ExecuteOnce will only execute one time.
            var taskResult = await task;

            Assert.Equal(1, await taskResult);
            Assert.Equal(1, await taskResult);
            Assert.Equal(1, await taskResult);
            Assert.Equal(1, await await task);
            Assert.Equal(1, await await task);
            Assert.Equal(1, await await task);
            Assert.Equal(1, task.Counter);
        }