You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
372 B

1 month ago
  1. import utils from "../utils.js";
  2. const callbackify = (fn, reducer) => {
  3. return utils.isAsyncFn(fn) ? function (...args) {
  4. const cb = args.pop();
  5. fn.apply(this, args).then((value) => {
  6. try {
  7. reducer ? cb(null, ...reducer(value)) : cb(null, value);
  8. } catch (err) {
  9. cb(err);
  10. }
  11. }, cb);
  12. } : fn;
  13. }
  14. export default callbackify;