Browse Source

[caller] Added normalising caller

0.7.0-breaking-rewrite
Muthu Kumar 6 years ago
parent
commit
85470a01c5
  1. 28
      src/lib/unit/caller.js

28
src/lib/unit/caller.js

@ -0,0 +1,28 @@
const { isPromise } = require('../../util');
const caller = (test, state) => {
let value, error;
try {
value = test(state);
} catch (e) {
error = e;
}
const promise = isPromise(value);
if (promise) {
return value
.then(res => ({ resolve: res, promise: true }))
.catch(rej => ({ rejection: rej, promise: true }));
} else {
return Promise.resolve({
...(!error && {value}),
...(error && {error}),
promise: false,
});
}
};
module.exports = caller;
Loading…
Cancel
Save