Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
noseratio committed Sep 3, 2020
1 parent 64ba0bc commit 337bc0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Coroutines are functions that yield and execute cooperatively, the concept that

Coroutines are useful for script-like scenarios where the code execution flow can be suspended and resumed after each logical step. Internally, they use some sort of programming language syntax sugar for generating state machines methods.

In the C# world, they have been popularized by [Unity game development platform](https://docs.unity3d.com/Manual/Coroutines.html), and Unity uses [`IEnumerator`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netcore-3.1)-style methods and `return yield` for that.
In the C# world, they have been popularized by [Unity game development platform](https://docs.unity3d.com/Manual/Coroutines.html), and Unity uses [`IEnumerator`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netcore-3.1)-style methods and `yield return` for that.

Prior to C# 8, it wasn't possible to combine `await` and `return yield` within the same method, making it difficult to use asynchrony inside coroutines. Now, with the compiler's support for `IAsyncEnumerable` it can be done naturally, and we're going to explore this option here.
Prior to C# 8, it wasn't possible to combine `await` and `yield return` within the same method, making it difficult to use asynchrony inside coroutines. Now, with the compiler's support for `IAsyncEnumerable` it can be done naturally, and we're going to explore this option here.

The execution environment for the code listed here is a Windows Forms .NET Core 3.1 app, but the same techniques can be used anywhere C# code runs.

Expand Down Expand Up @@ -152,7 +152,7 @@ In a few words, similar to how `IEnumerable` is used to produce a stream of data

And so by analogy with `IEnumerable`, we can use `IAsyncEnumerable`-methods to implement coroutines with async calls inside.

Before we get to a [real life example](###-A-real-life-scenario) of that, let's reproduce what we've done so far with `IEnumerable`-based `CoroutineA` and `CoroutineB`, but [using `IAsyncEnumerable` this time](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/AsyncCoroutineDemo.cs). We still want to run `return yield` continuations upon fixed timer intervals, but we also want to make sure there is no pending user input in the UI thread's message queue, before we proceed with any micro-task that runs on the UI thread. That's what [`inputIdler.Yield()`](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/InputIdler.cs) is for below:
Before we get to a [real life example](###-A-real-life-scenario) of that, let's reproduce what we've done so far with `IEnumerable`-based `CoroutineA` and `CoroutineB`, but [using `IAsyncEnumerable` this time](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/AsyncCoroutineDemo.cs). We still want to run `yield return` continuations upon fixed timer intervals, but we also want to make sure there is no pending user input in the UI thread's message queue, before we proceed with any micro-task that runs on the UI thread. That's what [`inputIdler.Yield()`](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/InputIdler.cs) is for below:

```C#
private static async IAsyncEnumerable<int> CoroutineA(
Expand Down
13 changes: 4 additions & 9 deletions async-coroutines-medium.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
---
title: # Asynchronous coroutines with C# 8.0 and `IAsyncEnumerable`
tags: ['csharp', 'dotnet', 'async', 'await', 'asynchronous', '.net', 'c#']
status: draft
---

# Asynchronous coroutines with C# 8.0 and `IAsyncEnumerable`

This article was originally published on [DEV.TO](https://dev.to/noseratio/asynchronous-coroutines-with-c-8-0-and-iasyncenumerable-2e04).
It might be more readable there, due to the platform's native markdown and code syntax highlighting support.
The repo with the **full source code can be found [here](https://github.com/noseratio/coroutines-talk)**.

## Introduction
Expand All @@ -17,9 +12,9 @@ Coroutines are functions that yield and execute cooperatively, the concept that

Coroutines are useful for script-like scenarios where the code execution flow can be suspended and resumed after each logical step. Internally, they use some sort of programming language syntax sugar for generating state machines methods.

In the C# world, they have been popularized by [Unity game development platform](https://docs.unity3d.com/Manual/Coroutines.html), and Unity uses [`IEnumerator`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netcore-3.1)-style methods and `return yield` for that.
In the C# world, they have been popularized by [Unity game development platform](https://docs.unity3d.com/Manual/Coroutines.html), and Unity uses [`IEnumerator`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netcore-3.1)-style methods and `yield return` for that.

Prior to C# 8, it wasn't possible to combine `await` and `return yield` within the same method, making it difficult to use asynchrony inside coroutines. Now, with the compiler's support for `IAsyncEnumerable` it can be done naturally, and we're going to explore this option here.
Prior to C# 8, it wasn't possible to combine `await` and `yield return` within the same method, making it difficult to use asynchrony inside coroutines. Now, with the compiler's support for `IAsyncEnumerable` it can be done naturally, and we're going to explore this option here.

The execution environment for the code listed here is a Windows Forms .NET Core 3.1 app, but the same techniques can be used anywhere C# code runs.

Expand Down Expand Up @@ -159,7 +154,7 @@ In a few words, similar to how `IEnumerable` is used to produce a stream of data

And so by analogy with `IEnumerable`, we can use `IAsyncEnumerable`-methods to implement coroutines with async calls inside.

Before we get to a [real life example](###-A-real-life-scenario) of that, let's reproduce what we've done so far with `IEnumerable`-based `CoroutineA` and `CoroutineB`, but [using `IAsyncEnumerable` this time](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/AsyncCoroutineDemo.cs). We still want to run `return yield` continuations upon fixed timer intervals, but we also want to make sure there is no pending user input in the UI thread's message queue, before we proceed with any micro-task that runs on the UI thread. That's what [`inputIdler.Yield()`](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/InputIdler.cs) is for below:
Before we get to a [real life example](###-A-real-life-scenario) of that, let's reproduce what we've done so far with `IEnumerable`-based `CoroutineA` and `CoroutineB`, but [using `IAsyncEnumerable` this time](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/AsyncCoroutineDemo.cs). We still want to run `yield return` continuations upon fixed timer intervals, but we also want to make sure there is no pending user input in the UI thread's message queue, before we proceed with any micro-task that runs on the UI thread. That's what [`inputIdler.Yield()`](https://github.com/noseratio/coroutines-talk/blob/main/Coroutines/InputIdler.cs) is for below:

```C#
private static async IAsyncEnumerable<int> CoroutineA(
Expand Down

0 comments on commit 337bc0c

Please sign in to comment.