Create a gist now

Instantly share code, notes, and snippets.

Embed
Break a promise
const broken = (promise, state = {
pending: true,
settled: false,
resolved: false,
rejected: false,
value: undefined,
error: undefined,
}) => (
promise.then(
x => {
state.resolved = true
state.value = x
},
x => {
state.rejected = true
state.error = x
}
),
promise.finally(() => {
state.pending = false
state.settled = true
}),
Object.keys(state)
.map(flag => ({
[flag]: () => state[flag]
})
.reduce(Object.assign, {})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment