Skip to content

Commit ed58560

Browse files
authored
Merge pull request #38 from berat/master
Promise API Çevirisi bitti.
2 parents 3763875 + 04cb5b0 commit ed58560

File tree

1 file changed

+71
-69
lines changed

1 file changed

+71
-69
lines changed
Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
# Promise API
22

3-
There are 5 static methods in the `Promise` class. We'll quickly cover their use cases here.
3+
`Promise`de 5 statik yöntem vardır. Kullanım davalarını burada hızlı bir şekilde ele alacağız.
44

55
## Promise.resolve
66

7-
The syntax:
7+
Söz dizimi:
88

99
```js
1010
let promise = Promise.resolve(value);
1111
```
1212

13-
Returns a resolved promise with the given `value`.
14-
15-
Same as:
13+
Verilen `value` ile çözülmüş olan bir söz verir.
14+
Buradaki gibi:
1615

1716
```js
1817
let promise = new Promise(resolve => resolve(value));
1918
```
2019

21-
The method is used when we already have a value, but would like to have it "wrapped" into a promise.
20+
Yöntem zaten bir değere sahipken kullanılır. Ancal bir söz içine "sarılmış" olmasını ister.
2221

23-
For instance, the `loadCached` function below fetches the `url` and remembers the result, so that future calls on the same URL return it immediately:
22+
Örneğin, `loadCached` fonksiyonu aşağıda `url`yi alır ve sonucu hatırlar. Böylece aynı URL'deki gelecekteki çağrılar hemen döndürülür.
2423

2524
```js
2625
function loadCached(url) {
@@ -41,59 +40,60 @@ function loadCached(url) {
4140
}
4241
```
4342

44-
We can use `loadCached(url).then(…)`, because the function is guaranteed to return a promise. That's the purpose `Promise.resolve` serves in the line `(*)`: it makes sure the interface is unified. We can always use `.then` after `loadCached`.
43+
`loadCached(url).then(…)` kullanabiliriz. Çünkü fonksiyonun bir söz döndürmesi garantilidir. Amaç `Promise.resolve` `(*)` doğrultusunda hizmet eder: Arayüzünün birleşik olduğundan emin olun. `.then`den sonra her zaman `loadCached` kullanabiliriz.
4544

4645
## Promise.reject
4746

48-
The syntax:
47+
Söz dizimi:
4948

5049
```js
5150
let promise = Promise.reject(error);
5251
```
5352

54-
Create a rejected promise with the `error`.
53+
`error` ile reddedilen bir söz oluşturun.
5554

56-
Same as:
55+
Yukarıdaki ile aynı:
5756

5857
```js
5958
let promise = new Promise((resolve, reject) => reject(error));
6059
```
6160

62-
We cover it here for completeness, rarely used in real code.
61+
Gerçek kodda nadiren kullanılan, bütünlük için buradayız.
6362

6463
## Promise.all
6564

66-
Let's say we want to run many promises to execute in parallel, and wait till all of them are ready.
65+
Paralel olarak yürütülmek için birçok söz vermek isteriz ve hepsinin hazır olmasını bekleriz.
6766

68-
For instance, download several URLs in parallel and process the content when all are done.
67+
Örneğin, paralel olarak birkaç URL'yi indirin ve hepsi bittiğinde içeriği işleyin.
6968

70-
That's what `Promise.all` is for.
69+
Bunun için `Promise.all`.
7170

72-
The syntax is:
71+
Söz dizimi:
7372

7473
```js
7574
let promise = Promise.all([...promises...]);
7675
```
7776

78-
It takes an array of promises (technically can be any iterable, but usually an array) and returns a new promise.
77+
Yeni bir söz alır ve bir dizi söz alır (technically can be any iterable, but usually an array.)
7978

80-
The new promise resolves when all listed promises are settled and has an array of their results.
79+
Yeni söz, listelenen tüm sözlerin yerine getirildiği ve sonuçların bir dizisine sahip olduğunda karar verir.
8180

82-
For instance, the `Promise.all` below settles after 3 seconds, and then its result is an array `[1, 2, 3]`:
81+
Örneğin, aşağıdaki `Promise.all` 3 saniye sonra yerleşir ve sonucu `[1, 2, 3]` dizisidir:
8382

8483
```js run
8584
Promise.all([
8685
new Promise(resolve => setTimeout(() => resolve(1), 3000)), // 1
8786
new Promise(resolve => setTimeout(() => resolve(2), 2000)), // 2
8887
new Promise(resolve => setTimeout(() => resolve(3), 1000)) // 3
89-
]).then(alert); // 1,2,3 when promises are ready: each promise contributes an array member
88+
]).then(alert); // 1,2,3 sözler hazır olduğunda: her söz bir dizi üyesine katkıda bulunur
9089
```
9190

92-
Please note that the relative order is the same. Even though the first promise takes the longest time to resolve, it is still first in the array of results.
91+
Lütfen göreli siparişin aynı olduğunu unutmayın. İlk sözün sözülmesi uzun sürse bile sonuçta ilk sırada yer almaktadır.
92+
93+
Yayın bir hile, bir dizi iş verisini bir dizi sözle eşleştirmek ve ardından bunu `Promise.all` içine kaydırmaktır.
9394

94-
A common trick is to map an array of job data into an array of promises, and then wrap that into `Promise.all`.
95+
Örneğin, eğer bir dizi URL'miz varsa hepsini şöyle getirebiliriz:
9596

96-
For instance, if we have an array of URLs, we can fetch them all like this:
9797

9898
```js run
9999
let urls = [
@@ -102,17 +102,18 @@ let urls = [
102102
'https://api.github.com/users/jeresig'
103103
];
104104

105-
// map every url to the promise of the fetch
105+
// Her URL'yi getirme sözüyle eşleyin
106106
let requests = urls.map(url => fetch(url));
107107

108-
// Promise.all waits until all jobs are resolved
108+
// Tüm işler çözülene kadar Promise.all bekler
109109
Promise.all(requests)
110110
.then(responses => responses.forEach(
111111
response => alert(`${response.url}: ${response.status}`)
112112
));
113113
```
114114

115-
A bigger example with fetching user information for an array of github users by their names (or we could fetch an array of goods by their ids, the logic is same):
115+
Bir dizi github kullanıcısı için kullanıcı bilgilerini adlarına göre almakla ilgili daha büyük bir örnek (veya bir mal dizisini kimlikleriyle alabiliriz. Mantık aynıdır):
116+
116117

117118
```js run
118119
let names = ['iliakan', 'remy', 'jeresig'];
@@ -121,22 +122,22 @@ let requests = names.map(name => fetch(`https://api.github.com/users/${name}`));
121122

122123
Promise.all(requests)
123124
.then(responses => {
124-
// all responses are ready, we can show HTTP status codes
125+
// Tüm cevaplar hazır. HTTP durum kodlarını gösterebiliriz
125126
for(let response of responses) {
126-
alert(`${response.url}: ${response.status}`); // shows 200 for every url
127+
alert(`${response.url}: ${response.status}`); // Her URL için 200 gösterir
127128
}
128129

129130
return responses;
130131
})
131-
// map array of responses into array of response.json() to read their content
132+
// Yanıt dizisini, içeriğini okumak için response.json() dizisine eşleyin
132133
.then(responses => Promise.all(responses.map(r => r.json())))
133-
// all JSON answers are parsed: "users" is the array of them
134+
// Tüm JSON cevapları ayrıştırılır: "users" bunların dizisidir.
134135
.then(users => users.forEach(user => alert(user.name)));
135136
```
136137

137-
**If any of the promises is rejected, `Promise.all` immediately rejects with that error.**
138+
**Eğer sözlerden herhangi biri ret edildiyse `Promise.all` bu hatayı hemen ret eder**
138139

139-
For instance:
140+
Örneğin:
140141

141142
```js run
142143
Promise.all([
@@ -148,57 +149,59 @@ Promise.all([
148149
]).catch(alert); // Error: Whoops!
149150
```
150151

151-
Here the second promise rejects in two seconds. That leads to immediate rejection of `Promise.all`, so `.catch` executes: the rejection error becomes the outcome of the whole `Promise.all`.
152+
İşte ikinci söz iki saniye içinde reddediyor. Bu `Promise.all`un hemen reddedilmesine yol açar, bu yüzden `.catch` çalıştırır: reddedilme hatası tüm `Promise.all`un sonucudur.
153+
152154

153155
```warn header="In case of an error, other promises are ignored"
154-
If one promise rejects, `Promise.all` immediately rejects, completely forgetting about the other ones in the list. Their results are ignored.
156+
Eğer bir söz reddederse, `Promise.all` derhal reddeder. Listedeki diğerlerini tamamen unutur. Onların sonuçları göz ardı edilir.
155157
156-
For example, if there are multiple `fetch` calls, like in the example above, and one fails, other ones will still continue to execute, but `Promise.all` don't watch them any more. They will probably settle, but the result will be ignored.
158+
Örneğin, yukarıdaki örnekte olduğu gibi birden fazla `fetch` çağrısı varsa ve biri başarısız olursa diğeri hala yürütülmeye devam eder. Ancak `Promise.all` artık onları izlememektedir. Muhtemelen yerleşecekler ancak sonuç göz ardı edilecektir.
157159
158-
`Promise.all` does nothing to cancel them, as there's no concept of "cancellation" in promises. In [another chapter](fetch-abort) we'll cover `AbortController` that aims to help with that, but it's not a part of the Promise API.
160+
`Promise.all` sözlerinde "iptal" kavramı olmadığı için onları iptal edecek hiçbir şey yapmaz. [Başka bir bölümde](fetch-abort) bu konuda yardımcı olmayı amaçlayan `AbortController`ı ele alacağız. Ancak bu Promise API'sinin bir parçası değil.
159161
```
160162

161163
````smart header="`Promise.all(...)` allows non-promise items in `iterable`"
162-
Normally, `Promise.all(...)` accepts an iterable (in most cases an array) of promises. But if any of those objects is not a promise, it's wrapped in `Promise.resolve`.
164+
Normalde, `Promise.all(...)` sözlerin yenilenebilir (çoğu durumda bir dizi) kabul eder. Ancak bu nesnelerden herhangi biri bir söz değilse `Promise.respove` içine sarılır.
165+
```
163166
164-
For instance, here the results are `[1, 2, 3]`:
167+
Örneğin burada `[1, 2, 3]` döner:
165168
166169
```js run
167170
Promise.all([
168171
new Promise((resolve, reject) => {
169172
setTimeout(() => resolve(1), 1000)
170173
}),
171-
2, // treated as Promise.resolve(2)
172-
3 // treated as Promise.resolve(3)
174+
2, // Promise.resolve(2) olarak kabul edildi.
175+
3 // Promise.resolve(3) olarak kabul edildi.
173176
]).then(alert); // 1, 2, 3
174177
```
175178

176-
So we are able to pass non-promise values to `Promise.all` where convenient.
179+
Bu yüzden uygun olmayan durumlarda `Promise.all`a söz etmeyen değerleri aktarabiliriz.
177180

178181
````
179182
180183
## Promise.allSettled
181184
182185
[recent browser="new"]
183186
184-
`Promise.all` rejects as a whole if any promise rejects. That's good in cases, when we need *all* results to go on:
187+
Herhangi bir söz reddederse `Promise.all` bir bütün olarak eder. Devam etmek için *all* sonuçlarına ihtiyacımız olduğunda bu iyidir:
185188
186189
```js
187190
Promise.all([
188191
fetch('/template.html'),
189192
fetch('/style.css'),
190193
fetch('/data.json')
191-
]).then(render); // render method needs them all
194+
]).then(render); // render yöntemi hepsine ihtiyaç duyuyor
192195
```
193196
194-
`Promise.allSettled` waits for all promises to settle: even if one rejects, it waits for the others. The resulting array has:
197+
`Promise.allSettled` tüm sözlerin yerine getirilmesini bekler: biri reddetse bile diğerini bekler. Sonuçta ortaya çıkan dizin:
195198
196-
- `{status:"fulfilled", value:result}` for successful responses,
197-
- `{status:"rejected", reason:error}` for errors.
199+
- `{status:"fulfilled", value:result}` başarılı cevap için,
200+
- `{status:"rejected", reason:error}` hatalar için.
198201
199-
For example, we'd like to fetch the information about multiple users. Even if one request fails, we're interested in the others.
202+
Örneğin, birden fazla kullanıcı hakkında bilgi edinmek istiyoruz. Bir istek başarısız olsa bile diğerleriyle de ilgileniyoruz
200203
201-
Let's use `Promise.allSettled`:
204+
Hadi `Promise.allSettled` kullanalım:
202205
203206
```js run
204207
let urls = [
@@ -220,7 +223,7 @@ Promise.allSettled(urls.map(url => fetch(url)))
220223
});
221224
```
222225
223-
The `results` in the line `(*)` above will be:
226+
Yukarıdaki satırdaki `results` `(*)` olacak:
224227
```js
225228
[
226229
{status: 'fulfilled', value: ...response...},
@@ -229,11 +232,11 @@ The `results` in the line `(*)` above will be:
229232
]
230233
```
231234
232-
So, for each promise we get its status and `value/reason`.
235+
Dolayısıyla, her söz için onun satütüsünü ve `değer/sebep` bilgisini alırız.
233236
234237
### Polyfill
235238
236-
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
239+
Eğer tarayıcı `Promise.allSettled` özelliğini desteklemiyorsa, polyfill kolaydır.
237240
238241
```js
239242
if(!Promise.allSettled) {
@@ -249,23 +252,23 @@ if(!Promise.allSettled) {
249252
}
250253
```
251254
252-
In this code, `promises.map` takes input values, turns into promises (just in case a non-promise was passed) with `p => Promise.resolve(p)`, and then adds `.then` handler to it.
255+
Bu kodda, `promises.map` giriş değerini alır, `p => Promise.resolve(p)` ile sözleri döndürüyor (sadece bir söz verilmemişse) ve sonra bunu işleyiciye ekler.
253256
254-
That handler turns a successful result `v` into `{state:'fulfilled', value:v}`, and an error `r` into `{state:'rejected', reason:r}`. That's exactly the format of `Promise.allSettled`.
257+
Bu işleyici başarılı bir `v` sonucusunu `{state:'fulfilled', value:v}` ve bir `r` hatasını `{state:'rejected', reason:r}` olarak çevirir. Bu `Promise.allSettled` formatıyla aynıdır.
255258
256-
Then we can use `Promise.allSettled` to get the results or *all* given promises, even if some of them reject.
259+
Sonra bazı sonuçları reddetse bile sonuçları almak ya da *all* sözleri vermek için `Promise.allSettled`i kullanabiliriz.
257260
258261
## Promise.race
259262
260-
Similar to `Promise.all`, it takes an iterable of promises, but instead of waiting for all of them to finish, it waits for the first result (or error), and goes on with it.
263+
`Promise.all` benzer şekilde sözler yenilenebilir. Ancak hepsinin bitmesini beklemek yerine ilk sonucu (veya hatayı) bekler ve devam eder.
261264
262-
The syntax is:
265+
Söz dizimi:
263266
264267
```js
265268
let promise = Promise.race(iterable);
266269
```
267270
268-
For instance, here the result will be `1`:
271+
Mesela burada sonuç `1` olacak:
269272
270273
```js run
271274
Promise.race([
@@ -275,18 +278,17 @@ Promise.race([
275278
]).then(alert); // 1
276279
```
277280
278-
So, the first result/error becomes the result of the whole `Promise.race`. After the first settled promise "wins the race", all further results/errors are ignored.
279-
280-
## Summary
281+
Böylece ilk sonuç/hata bütün `Promise.race` sonucu olur. İlk kararlaştırılan sözün ardından "yarışı kazanır", diğer tüm sonuçlar/hatalar göz ardı edilir
281282
282-
There are 5 static methods of `Promise` class:
283+
## Özetle
283284
284-
1. `Promise.resolve(value)` -- makes a resolved promise with the given value.
285-
2. `Promise.reject(error)` -- makes a rejected promise with the given error.
286-
3. `Promise.all(promises)` -- waits for all promises to resolve and returns an array of their results. If any of the given promises rejects, then it becomes the error of `Promise.all`, and all other results are ignored.
287-
4. `Promise.allSettled(promises)` (a new method) -- waits for all promises to resolve or reject and returns an array of their results as object with:
288-
- `state`: `'fulfilled'` or `'rejected'`
289-
- `value` (if fulfilled) or `reason` (if rejected).
290-
5. `Promise.race(promises)` -- waits for the first promise to settle, and its result/error becomes the outcome.
285+
`Promise` sınıfının 5 statik metodu vardır:
291286
292-
Of these five, `Promise.all/allSettled` are the most common in practice.
287+
1. `Promise.resolve(value)` -- verilen değerle çözümlenmiş bir söz verir.
288+
2. `Promise.reject(error)` -- verilen hata ile reddedilen bir söz verir..
289+
3. `Promise.all(promises)` -- çözmek için tüm sözleri bekler ve sonuçlarının bir dizisini döndürür. Eğer verilen sözlerden herhangi biri reddederse o zaman `Promise.all` hatası olur ve diğer tüm sonuçlar göz ardı edilir.
290+
4. `Promise.allSettled(promises)` (yeni bir metod) -- tüm sözlerin çözülmesini veya reddedilmesini bekler ve sonuçlarının bir dizisini nesne olarak döndürür.
291+
- `state`: `'fulfilled'` yada `'rejected'`
292+
- `value` (if fulfilled) ya da `reason` (reddedilirse).
293+
5. `Promise.race(promises)` -- ilk yerlmeşmeye söz vermek için bekler ve sonucu/hatası sonuç olur.
294+
Bu beş maddede `Promise.all/allSettled` en yaygın kullanılanıdır.

0 commit comments

Comments
 (0)