Skip to content

Commit 80a0cbf

Browse files
committed
Edit info about states of promises
1 parent b367f22 commit 80a0cbf

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/content/2/en/part2c.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,12 @@ The documentation on Mozilla's site states the following about promises:
279279
280280
In other words, a promise is an object that represents an asynchronous operation. A promise can have three distinct states:
281281

282-
- The promise is <i>pending</i>: It means that the final value (one of the following two) is not available yet.
283-
- The promise is <i>fulfilled</i>: It means that the operation has been completed and the final value is available, which generally is a successful operation. This state is sometimes also called <i>resolved</i>.
282+
- The promise is <i>pending</i>: It means that the asynchronous operation corresponding to the promise has not yet finnished and the final value is not available yet.
283+
- The promise is <i>fulfilled</i>: It means that the operation has been completed and the final value is available, which generally is a successful operation.
284284
- The promise is <i>rejected</i>: It means that an error prevented the final value from being determined, which generally represents a failed operation.
285285

286+
There are many details related to promises, but understanding these three states is sufficient for us for now. If you want, you can read more about promises in [Mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
287+
286288
The first promise in our example is <i>fulfilled</i>, representing a successful _axios.get('http://localhost:3001/notes')_ request. The second one, however, is <i>rejected</i>, and the console tells us the reason. It looks like we were trying to make an HTTP GET request to a non-existent address.
287289

288290
If, and when, we want to access the result of the operation represented by the promise, we must register an event handler to the promise. This is achieved using the method <em>then</em>:

src/content/2/fi/osa2c.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ Mozillan dokumentaatio kertoo promisesta seuraavaa:
282282
Promise siis edustaa asynkronista operaatiota. Promise voi olla kolmessa eri tilassa:
283283

284284
- Aluksi promise on <i>pending</i>, eli promisea vastaava asynkroninen operaatio ei ole vielä tapahtunut.
285-
- Jos operaatio päättyy onnistuneesti, promise menee tilaan <i>fulfilled</i>, josta joskus käytetään myös nimitystä <i>resolved</i>.
285+
- Jos operaatio päättyy onnistuneesti, promise menee tilaan <i>fulfilled</i>.
286286
- Kolmas mahdollinen tila on <i>rejected</i>, ja se edustaa epäonnistunutta operaatiota.
287287

288+
Promiseihin liittyy paljon yksityiskohtia, mutta näiden kolmen tilan ymmärtäminen riittää meille toistaiseksi hyvin. Voit halutessasi lukea promiseista tarkemmin [Mozillan dokumentaatiosta](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
289+
288290
Esimerkkimme ensimmäinen promise on <i>fulfilled</i>, eli vastaa onnistunutta <em>axios.get('http://localhost:3001/notes')</em> pyyntöä. Promiseista toinen taas on <i>rejected</i>. Syy selviää konsolista, eli yritimme tehdä HTTP GET ‑pyyntöä osoitteeseen, jota ei ole olemassa.
289291

290292
Jos ja kun haluamme tietoon promisea vastaavan operaation tuloksen, tulee promiselle rekisteröidä tapahtumankuuntelija. Tämä tapahtuu metodilla <em>then</em>:

0 commit comments

Comments
 (0)