Skip to content

Instantly share code, notes, and snippets.

@tom-sherman
Last active July 11, 2021 10:24
Show Gist options
  • Save tom-sherman/77aacd62ac46d545f6ae6c4c6de5fc05 to your computer and use it in GitHub Desktop.
Save tom-sherman/77aacd62ac46d545f6ae6c4c6de5fc05 to your computer and use it in GitHub Desktop.
module FetchMachine = Machine({
type state = [#idle | #loading | #success | #failure]
type event = [#FETCH | #RESOLVE | #REJECT | #RETRY]
type context = {retries: int}
let id = "fetch"
let initial = #idle
let states = [
State({
name: #idle,
on: [(#FETCH, #loading)],
}),
State({
name: #loading,
on: [(#RESOLVE, #success), (#REJECT, #failure)],
}),
Final({
name: #success,
}),
State({
name: #failure,
on: [(#RETRY, #loading)],
}),
]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment