private async IAsyncEnumerable <string> CoroutineA(
            ICoroutineProxy <string> coroutineProxy,
            [EnumeratorCancellation] CancellationToken token)
        {
            await using var coroutine = await coroutineProxy.AsAsyncEnumerator(token);

            const string name = "A";
            var          i    = 0;

            // yielding 1
            Trace.WriteLine($"{name} about to yeild: {++i}", TRACE_CATEGORY);
            yield return($"{i} from {name}");

            // receiving
            if (!await coroutine.MoveNextAsync())
            {
                yield break;
            }
            Trace.WriteLine($"{name} received: {coroutine.Current}", TRACE_CATEGORY);

            // yielding 2
            Trace.WriteLine($"{name} about to yeild: {++i}", TRACE_CATEGORY);
            yield return($"{i} from {name}");

            // receiving
            if (!await coroutine.MoveNextAsync())
            {
                yield break;
            }
            Trace.WriteLine($"{name} received: {coroutine.Current}", TRACE_CATEGORY);

            // yielding 3
            Trace.WriteLine($"{name} about to yeild: {++i}", TRACE_CATEGORY);
            yield return($"{i} from {name}");
        }
예제 #2
0
 public async static Task <IAsyncEnumerator <T> > AsAsyncEnumerator <T>(
     this ICoroutineProxy <T> @this,
     CancellationToken token = default)
 {
     return((await @this.AsAsyncEnumerable(token)).GetAsyncEnumerator(token));
 }