Created
November 12, 2019 21:13
-
-
Save kalda341/c5c1d30396282185a53b6922e5587325 to your computer and use it in GitHub Desktop.
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 saveTask = useTask(function*() { | |
yield timeout(1000); | |
yield doSaveTask.perform(); | |
}, 'RESTARTABLE'); | |
const doSaveTask = useTask(function*() { | |
// Ensure that we ALWAYS have the most recent project state | |
const currentState = yield getMostRecentProjectState(); | |
const { revision } = yield updateProject(authHeaders, currentState); | |
yield _setProjectState(assoc('revision', revision)); | |
// We should never have multiple of these running at the same time | |
}, 'ENQUEUE'); | |
const setProjectState = newData => { | |
_setProjectState(assoc('data', newData)); | |
saveTask.perform(); | |
}; | |
const getMostRecentProjectState = () => | |
new Promise(resolve => _setProjectState(tap(resolve))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment