Skip to content

Commit

Permalink
Update style and remove dublicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed Feb 22, 2024
1 parent 99ce72d commit 9a3518a
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ const timeoutify = (promise, msec) =>
timer = null;
reject(new Error(`Timeout of ${msec}ms reached`, 'ETIMEOUT'));
}, msec);
promise.then(
(result) => {
if (!timer) return;
clearTimeout(timer);
resolve(result);
},
(error) => {
if (!timer) return;
clearTimeout(timer);
reject(error);
},
);
const execute = (err, res) => {
if (!timer) return;
clearTimeout(timer);
if (err) return void reject(err);
resolve(res);
};
promise.then((res) => void execute(null, res), execute);
});

module.exports = { toBool, timeout, delay, timeoutify };

0 comments on commit 9a3518a

Please sign in to comment.