public async IAsyncEnumerable <TaskResult <int> > EmitCounter(TrivialCounterTask t) { yield return(await t); yield return(await t); yield return(await new TrivialCounterSubTask(await t)); }
public async Task TaskCaching_Test() { var task = new TrivialCounterTask(); await foreach (var i in EmitCounter(task)) { ; } Assert.Equal(1, task.Counter); }
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); }