Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Created November 7, 2019 01:42
Show Gist options
  • Save davidkpiano/9bf435ec402045d7f36844af73ed8d22 to your computer and use it in GitHub Desktop.
Save davidkpiano/9bf435ec402045d7f36844af73ed8d22 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const getBlobMetadata = () => new Promise(res => {
setTimeout(() => {
console.log('yeah')
res({
Path: 'somepath.csv'
});
}, 2000)
});
const readFile = () => new Promise((res, rej) => {
setTimeout(() => {
if (Math.random() < .4) {
res([1, 2, 3, 4, 5]);
} else {
rej();
}
}, 1000)
});
const machine = Machine({
id: 'location-based data processing',
initial: 'pending',
context: {
blobMeta: null,
users: null
},
states: {
pending: {
on: {
'HTTP Request Trigger': 'get blob metadata'
}
},
'get blob metadata': {
invoke: {
id: 'blob metadata task',
src: getBlobMetadata,
onDone: {
target: 'create container group',
actions: assign({
blobMeta: (_, e) => e.data
})
}
}
},
'create container group': {
invoke: {
id: 'container group task',
src: () => () => {}, // fire-and-forget
},
states: {
'waiting for file': {
invoke: {
id: 'read file task',
src: readFile,
onDone: {
target: 'file found',
actions: assign({
users: (_, e) => e.data
})
},
onError: '.'
}
},
'file found': {
type: 'final'
}
},
onDone: 'success'
},
'success': {
type: 'final'
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment