You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/blog-md/2025/17-12/generator-generation.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Our end goal is going to be to define an abstraction that will allow us to conve
12
12
13
13
## Promises
14
14
15
-
Before diving into the complexity of generators, we're going to quickly kick off with a little introduction to `Promises` and how they relate to `async/await` and callback code
15
+
Before diving into the complexity of generators, we're going to quickly kick off with a little introduction to `Promises` and how they relate to `async/await` and callback-based code
16
16
17
17
Promises are used to make async code easier to work with and JavaScript has some nice syntax - like `async/await` that makes code using promises easier follow and understand. They're also the common way to represent async operations which is exactly what we're going to use them for
18
18
@@ -76,7 +76,7 @@ async function doWork(){
76
76
77
77
The `doWork` function returns `Promise`, this is because the `async` keyword is some syntax sugar for creating a `Promise`
78
78
79
-
### Promises vs Async
79
+
### Promises Vs Async
80
80
81
81
For the sake of understanding, all that the `async` keyword does allow us to remove the `Promise` construction from our function - `async` functions are simply functions that return a `Promise` - these are alternative syntax for the same thing - so, the following two functions are the same:
82
82
@@ -88,7 +88,7 @@ async function getNumber() {
88
88
}
89
89
```
90
90
91
-
Using an explict`Promise`:
91
+
Using an explicit`Promise`:
92
92
93
93
```ts
94
94
function getNumber() {
@@ -239,7 +239,7 @@ This also applies for the iterators above, I just find it so much more interesti
239
239
240
240
### Async Generators
241
241
242
-
Now, we're taking one more step - what if I wanted to do some long running task between each `yield`? This could be anything from waiting for a `Promise` to resolve, or a network request, or some user event (oh wow - there's an idea for multi-step forms!)
242
+
Now, we're taking one more step - what if I wanted to do some long running task between each `yield`? This could be anything from waiting for a `Promise` to resolve, or a network request, or some user event (oh wow - there's an idea for multistep forms!)
243
243
244
244
Async Generators enable us to use promises in our iterators. Let's take a look at how we might define an async version of our `countTo` generator above:
245
245
@@ -273,7 +273,7 @@ Let's start with the sync version
273
273
274
274
### Inside a Sync Generator
275
275
276
-
So if we re-define our `countTo` generator without using the `function*` and `yield` syntax sugar, we'll see something like this:
276
+
So if we redefine our `countTo` generator without using the `function*` and `yield` syntax sugar, we'll see something like this:
277
277
278
278
```ts
279
279
function countTo(max:number):Generator<number> {
@@ -388,7 +388,7 @@ Assume for whatever reason that we want to be able to take functions like this a
388
388
function countIntervalGenerator(max:number):AsyncGenerator<number> {}
389
389
```
390
390
391
-
For now, let's asume we've got a method called `createGenerator` that returns everything we need to hook up a generator and return it, this looks something like this:
391
+
For now, let's assume we've got a method called `createGenerator` that returns everything we need in order to hook up a generator and return it, this looks something like this:
392
392
393
393
```ts
394
394
function countIntervalGenerator(max:number):AsyncGenerator<number> {
0 commit comments