|
@ -2,10 +2,11 @@ const { isPromise } = require('../../util'); |
|
|
|
|
|
|
|
|
const caller = (test, state) => { |
|
|
const caller = (test, state) => { |
|
|
|
|
|
|
|
|
let value, error; |
|
|
let value, error, errored; |
|
|
try { |
|
|
try { |
|
|
value = test(state); |
|
|
value = test(state); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
|
|
|
errored = true; |
|
|
error = e; |
|
|
error = e; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -13,12 +14,13 @@ const caller = (test, state) => { |
|
|
|
|
|
|
|
|
if (promise) { |
|
|
if (promise) { |
|
|
return value |
|
|
return value |
|
|
.then(res => ({ resolve: res, promise: true })) |
|
|
.then(res => ({ status: 'ok', resolve: res, promise: true })) |
|
|
.catch(rej => ({ rejection: rej, promise: true })); |
|
|
.catch(rej => ({ status: 'notOk', rejection: rej, promise: true })); |
|
|
} else { |
|
|
} else { |
|
|
return Promise.resolve({ |
|
|
return Promise.resolve({ |
|
|
...(!error && {value}), |
|
|
status: errored ? 'notOk' : 'ok', |
|
|
...(error && {error}), |
|
|
...(!errored && { value }), |
|
|
|
|
|
...(errored && { error }), |
|
|
promise: false, |
|
|
promise: false, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|