Skip to content

Instantly share code, notes, and snippets.

@evan-brass
Last active July 24, 2019 00:24
Show Gist options
  • Select an option

  • Save evan-brass/53ac9f02fe29d391b96b0f575a6cf68a to your computer and use it in GitHub Desktop.

Select an option

Save evan-brass/53ac9f02fe29d391b96b0f575a6cf68a to your computer and use it in GitHub Desktop.
function* testHelper() {
console.log('Entering Helper');
yield delay(1000); // State H-1
console.log('Helper: Transition 1');
yield delay(1000); // State H-2
console.log('Helper: Transition 2');
return 5;
}
function* test() {
try {
console.log('About to call testHelper');
const value = yield* testHelper(); // State T-1
console.log(`Got ${value} from testHelper`);
} finally {
console.log('starting the finally');
yield delay(1000); // State T-2
console.log('finishing the finally');
}
return 'success';
}
const a = cancelable(test());
a.then(result => console.log('cancelable resolved with', result));
// a.cancel() to cancel the machine at any time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment