Skip to content

Commit 3d1ecd1

Browse files
committed
Fixed formatting
1 parent d885096 commit 3d1ecd1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

docs/actions.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
In this section, we'll how we can use `action` as a safe alternative to
1+
In this section, we'll see how we can use `action` as a safe alternative to
22
the [Promise constructor][promise-constructor].
33

44
## Example: Sleep
55

66
Let's revisit our sleep operation from the [introduction to
77
operations](../operations):
88

9-
109
```js
1110
export function sleep(duration: number): Operation<void> {
1211
return action((resolve) => {
@@ -57,7 +56,8 @@ an abort signal was there without sacrificing any clarity in achieving it.
5756

5857
## Action Constructor
5958

60-
The [`action()`][action] function provides a callback based API to create Effection operations. You don't need it all that often, but when you do it functions almost exactly like the
59+
The [`action()`][action] function provides a callback based API to create Effection operations.
60+
You don't need it all that often, but when you do it functions almost exactly like the
6161
[promise constructor][promise-constructor]. To see this, let's
6262
use [one of the examples from MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise#examples)
6363
that uses promises to make a crude replica of the global [`fetch()`][fetch]
@@ -89,7 +89,7 @@ function* fetch(url) {
8989
xhr.onload = () => resolve(xhr.responseText);
9090
xhr.onerror = () => reject(xhr.statusText);
9191
xhr.send();
92-
return () => { } // "finally" function place holder.
92+
return () => {}; // "finally" function place holder.
9393
});
9494
}
9595
```
@@ -108,11 +108,11 @@ until _both_ requests are have received a response.
108108
```js
109109
await Promise.race([
110110
fetch("https://openweathermap.org"),
111-
fetch("https://open-meteo.org")
112-
])
111+
fetch("https://open-meteo.org"),
112+
]);
113113
```
114114

115-
With Effection, this is easily fixed by calling `abort()` in the finally function to
115+
With Effection, this is easily fixed by calling `abort()` in the finally function to
116116
make sure that the request is cancelled when it is either resolved, rejected, or
117117
passes out of scope.
118118

@@ -124,15 +124,16 @@ function* fetch(url) {
124124
xhr.onload = () => resolve(xhr.responseText);
125125
xhr.onerror = () => reject(xhr.statusText);
126126
xhr.send();
127-
return () => { xhr.abort(); }; // called in all cases
127+
return () => {
128+
xhr.abort();
129+
}; // called in all cases
128130
});
129131
}
130132
```
131133

132-
>💡Almost every usage of the [promise concurrency primitives][promise-concurrency]
134+
> 💡Almost every usage of the [promise concurrency primitives][promise-concurrency]
133135
> will contain bugs born of leaked effects.
134136
135-
136137
[abort-signal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
137138
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/fetch
138139
[promise-constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
@@ -141,4 +142,4 @@ function* fetch(url) {
141142
[scope]: ./scope
142143
[spawn-suspend]: ./spawn#suspend
143144
[action]: /api/v3/action
144-
[all]: /api/v3/all
145+
[all]: /api/v3/all

0 commit comments

Comments
 (0)