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
Promisification -- is a long word for a simple transform. It's conversion of a function that accepts a callback into a function returning a promise.
3
+
Promisification -- basit bir dönüşüm için uzun bir kelime. Bu callback kabul eden bir fonksiyonun promise dönen bir fonksiyona dönüştürülmesidir.
4
4
5
-
To be more precise, we create a wrapper-function that does the same, internally calling the original one, but returns a promise.
5
+
Daha kesin olmak gerekirse, aynı şeyi yapan, orjinali dahili olarak çağıran, fakat bir promise dönen bir sarmalayıcı fonksiyon oluşturuyoruz.
6
6
7
-
Such transforms are often needed in real-life, as many functions and libraries are callback-based. But promises are more convenient. So it makes sense to promisify those.
7
+
Birçok fonksiyon ve kütüphane callback-based olduğundan, bu tür dönüşümlere gerçek hayatta ihtiyaç duyulur.
8
8
9
-
For instance, we have`loadScript(src, callback)`from the chapter <info:callbacks>.
9
+
Örneğin, <info:callbacks> bölümünden`loadScript(src, callback)`var.
10
10
11
11
```js run
12
12
functionloadScript(src, callback) {
13
13
let script =document.createElement('script');
14
14
script.src= src;
15
15
16
16
script.onload= () =>callback(null, script);
17
-
script.onerror= () =>callback(newError(`Script load error for ${src}`));
17
+
script.onerror= () =>callback(newError(`${src} için script yüklenme hatası`));
Here we assume that the original function expects a callback with two arguments `(err, result)`. That's what we encounter most often. Then our custom callback is in exactly the right format, and `promisify`works great for such a case.
76
+
Burada orijinal fonksiyonun iki argümanlı bir callback beklediğini varsayıyoruz `(err, result)`. En sık karşılaştığımız şey bu. O zaman özel callback'imiz tam olarak doğru biçimdedir ve `promisify`böyle bir durum için harika çalışır.
77
77
78
-
But what if the original `f`expects a callback with more arguments`callback(err, res1, res2)`?
78
+
Ama ya orijinal `f`daha fazla argümanlı bir callback bekliyorsa`callback(err, res1, res2)`?
79
79
80
-
Here's a modification of `promisify` that returns an array of multiple callback results:
80
+
İşte bir dizi çoklu callback sonucu döndüren bir `promisify` değişikliği:
81
81
82
82
```js
83
-
// promisify(f, true) to get array of results
83
+
//bir dizi sonuç elde etmek için promisify(f, true)
//resolve with all callback results if manyArgs is specified
91
+
// manyArgs belirtilirse tüm callback sonuçlarıyla çözümle
92
92
*!*resolve(manyArgs ? results : results[0]);*/!*
93
93
}
94
94
}
@@ -100,19 +100,19 @@ function promisify(f, manyArgs = false) {
100
100
};
101
101
};
102
102
103
-
//usage:
103
+
// kullanımı:
104
104
f = promisify(f, true);
105
105
f(...).then(arrayOfResults => ..., err => ...)
106
106
```
107
107
108
-
In some cases, `err`may be absent at all: `callback(result)`, or there's something exotic in the callback format, then we can promisify such functions without using the helper, manually.
108
+
Bazı durumlarda `err` olmayabilir: `callback(result)` veya callback biçiminde farklı bir şey varsa, bu tür fonksiyonları helper kullanmadan manuel olarak promisify edebiliriz.
109
109
110
-
There are also modules with a bit more flexible promisification functions, e.g. [es6-promisify](https://github.com/digitaldesignlabs/es6-promisify). In Node.js, there's a built-in `util.promisify`function for that.
110
+
Biraz daha esnek promisification fonksiyonlarına sahip modüller de vardır, örnek [es6-promisify](https://github.com/digitaldesignlabs/es6-promisify). Node.js'debununiçinyerleşikbir`util.promisify`fonksiyonuvardır.
111
111
112
112
```smart
113
-
Promisification is a great approach, especially when you use `async/await`(see the next chapter), but not a total replacement for callbacks.
113
+
Promisification, özellikle `async/await`kullandığınızda harika bir yaklaşımdır (sonraki bölüme bakın), ancak callbacklerin tam olarak yerine geçmez.
114
114
115
-
Remember, a promise may have only one result, but a callback may technically be called many times.
115
+
Unutmayın, bir promise yalnızca bir sonuca sahip olabilir, ancak bir callback teknik olarak birçok kez çağrılabilir.
116
116
117
-
So promisification is only meant for functions that call the callback once. Further calls will be ignored.
117
+
Bu nedenle, promisification yalnızca callback'i bir kez çağıran fonksiyonlar içindir. Diğer çağırmalar göz ardı edilecektir.
0 commit comments