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
As we know, `fetch`returns a promise. And JavaScript generally has no concept of "aborting" a promise. So how can we abort a `fetch`?
4
+
Comme nous le savons, `fetch`renvoie une promesse. Et JavaScript n'a généralement pas le concept "d'abandonner" une promesse. Alors, comment pouvons-nous abandonner un `fetch`?
5
5
6
-
There's a special built-in object for such purposes: `AbortController`, that can be used to abort not only `fetch`, but other asynchronous tasks as well.
6
+
Il existe un objet intégré spécial dédié : `AbortController`, qui peut être utilisé pour abandonner non seulement un `fetch`, mais aussi d'autres tâches asynchrones.
7
7
8
-
The usage is pretty simple:
8
+
L'utilisation est assez simple:
9
9
10
-
-Step 1: create a controller:
10
+
-Étape 1 : créez un contrôleur :
11
11
12
12
```js
13
13
let controller =newAbortController();
14
14
```
15
15
16
-
A controller is an extremely simple object.
16
+
Un contrôleur est un objet extrêmement simple.
17
17
18
-
-It has a single method `abort()`, and a single property`signal`.
let results = await Promise.all([...fetchJobs, ourJob]);
116
116
117
-
// if controller.abort() is called from elsewhere,
118
-
// it aborts all fetches and ourJob
117
+
// si controller.abort() est appelée d'ailleurs,
118
+
//elle interrompt tous les fetches et ourJob
119
119
```
120
120
121
-
So `AbortController` is not only for `fetch`, it's a universal object to abort asynchronous tasks, and`fetch`has built-in integration with it.
121
+
Donc`AbortController`n'est pas seulement pour`fetch`, c'est un objet universel pour abandonner les tâches asynchrones, et`fetch`a une intégration native avec lui.
0 commit comments