Created
November 7, 2019 01:42
-
-
Save davidkpiano/9bf435ec402045d7f36844af73ed8d22 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
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