Skip to content

Instantly share code, notes, and snippets.

@dherman
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dherman/11016589 to your computer and use it in GitHub Desktop.
Save dherman/11016589 to your computer and use it in GitHub Desktop.
how canceling a cancelation could arise organically
for (let x of foo()) {
...
// generator gets canceled at some point before it completes the iteration
break;
...
}
function* foo() {
...
try {
// imagine cancellation happens here while delegating
... yield* delegate() ...
} catch (e) {
// catch errors and keep executing
log(e)
}
// yield more values after the delegation
... yield ...
}
// delegate generator function has some internal cleanup code
function* delegate() {
...
try {
// imagine cancellation happens here inside the try
... yield ...
} finally {
// cleanup code uses a helper
... helper() ...
}
...
}
// some helper function that can sometimes throw an exception
function helper() {
... throw ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment