Last active
February 8, 2019 18:20
-
-
Save hnordt/c5268c2ab9f9a19e2ad576dd7115b2f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To see the diagram copy this code and paste in https://statecharts.github.io/xstate-viz/ | |
const lazyPromiseMachine = Machine({ | |
id: "lazyPromise", | |
initial: "idle", | |
context: { | |
exec: () => Promise.resolve() | |
}, | |
states: { | |
idle: { | |
on: { | |
RUN: "resolving" | |
} | |
}, | |
resolving: { | |
invoke: { | |
src: context => context.exec(), | |
onDone: "fulfilled", | |
onError: "rejected" | |
}, | |
on: { | |
CANCEL: "canceled" | |
} | |
}, | |
canceled: { | |
on: { | |
RERUN: "resolving" | |
} | |
}, | |
fulfilled: { | |
type: "final" | |
}, | |
rejected: { | |
type: "final" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment