Skip to content

Commit

Permalink
Improve promisify function
Browse files Browse the repository at this point in the history
Now handles callbacks with one argument & no error
  • Loading branch information
superandrew213 committed Jan 2, 2018
1 parent dad0ce4 commit ffa363f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const { InAppUtils } = NativeModules;
const InAppUtilsEmitter = new NativeEventEmitter(InAppUtils);

const promisify = fn => (...args) => new Promise((resolve, reject) => {
fn(...args, (err, res) => err ? reject(err) : resolve(res));
fn(...args, (err, res) => {
if (err !== undefined && err instanceof Error) reject(err);
// If only one argument is given and it's not an error
if (err !== undefined && res === undefined) resolve(err);
resolve(res);
});
});

const IAU = Platform.select({
Expand Down

0 comments on commit ffa363f

Please sign in to comment.