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
Copy file name to clipboardExpand all lines: 1-js/11-async/06-promisify/article.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -27,11 +27,11 @@ Let's promisify it. The new `loadScriptPromise(src)` function achieves the same
27
27
letloadScriptPromise=function(src) {
28
28
returnnewPromise((resolve, reject) => {
29
29
loadScript(src, (err, script) => {
30
-
if (err) reject(err)
30
+
if (err) reject(err);
31
31
elseresolve(script);
32
32
});
33
-
})
34
-
}
33
+
});
34
+
};
35
35
36
36
// usage:
37
37
// loadScriptPromise('path/script.js').then(...)
@@ -62,7 +62,7 @@ function promisify(f) {
62
62
f.call(this, ...args); // call the original function
63
63
});
64
64
};
65
-
};
65
+
}
66
66
67
67
// usage:
68
68
let loadScriptPromise =promisify(loadScript);
@@ -94,11 +94,11 @@ function promisify(f, manyArgs = false) {
94
94
f.call(this, ...args);
95
95
});
96
96
};
97
-
};
97
+
}
98
98
99
99
// usage:
100
100
f =promisify(f, true);
101
-
f(...).then(arrayOfResults=>..., err=>...)
101
+
f(...).then(arrayOfResults=>..., err=>...);
102
102
```
103
103
104
104
For more exotic callback formats, like those without `err` at all: `callback(result)`, we can promisify such functions manually without using the helper.
0 commit comments