Files
vanillajs-seed/node_modules/try-to-catch/lib/try-to-catch.js
2020-05-26 10:37:57 +02:00

18 lines
283 B
JavaScript

'use strict';
module.exports = async (fn, ...args) => {
check(fn);
try {
return [null, await fn(...args)];
} catch(e) {
return [e];
}
};
function check(fn) {
if (typeof fn !== 'function')
throw Error('fn should be a function!');
}