1 | ;
|
2 |
|
3 | /**
|
4 | * Calls a callback caller that calls a callback call for async instead of using promises.
|
5 | *
|
6 | * @param {Function} fn function to call
|
7 | * @param [args] arguments to call function with
|
8 | * @return {Promise} It returns a promise which resolves on callback call.
|
9 | */
|
10 | function callback(fn, ...args)
|
11 | {
|
12 | return new Promise(function (resolve, reject)
|
13 | {
|
14 | function handler(err, result)
|
15 | {
|
16 | if (err)
|
17 | {
|
18 | reject(new Error(err));
|
19 | }
|
20 | else
|
21 | {
|
22 | resolve(result);
|
23 | }
|
24 | }
|
25 | args.push(handler);
|
26 | fn(...args);
|
27 | });
|
28 | }
|
29 |
|
30 | module.exports = callback;
|