Skip to content

Instantly share code, notes, and snippets.

@hnordt
Last active February 8, 2019 18:20
Show Gist options
  • Save hnordt/c5268c2ab9f9a19e2ad576dd7115b2f2 to your computer and use it in GitHub Desktop.
Save hnordt/c5268c2ab9f9a19e2ad576dd7115b2f2 to your computer and use it in GitHub Desktop.
// 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