Skip to content

Instantly share code, notes, and snippets.

@ujeenator
Created October 29, 2016 20:11
Show Gist options
  • Select an option

  • Save ujeenator/7a795e1ceb6602a7d940536a0ce72e02 to your computer and use it in GitHub Desktop.

Select an option

Save ujeenator/7a795e1ceb6602a7d940536a0ce72e02 to your computer and use it in GitHub Desktop.
import delay from 'delay';
async function fooActionCreator(){
try {
const result = await Promise.race([
fetch('/data', {cancellation}),
delay(10000).then(() => throw 'CANCELLED'),
]);
return {type: 'REQUEST_DONE', result};
} catch(ex) {
if (ex === CANCELLED) {
return {type: 'REQUEST_CANCELLED'};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment