main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
372 bytes
|
Line | |
---|
1 | import utils from "../utils.js";
|
---|
2 |
|
---|
3 | const callbackify = (fn, reducer) => {
|
---|
4 | return utils.isAsyncFn(fn) ? function (...args) {
|
---|
5 | const cb = args.pop();
|
---|
6 | fn.apply(this, args).then((value) => {
|
---|
7 | try {
|
---|
8 | reducer ? cb(null, ...reducer(value)) : cb(null, value);
|
---|
9 | } catch (err) {
|
---|
10 | cb(err);
|
---|
11 | }
|
---|
12 | }, cb);
|
---|
13 | } : fn;
|
---|
14 | }
|
---|
15 |
|
---|
16 | export default callbackify;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.