Last active
August 29, 2015 14:00
-
-
Save dherman/11016589 to your computer and use it in GitHub Desktop.
how canceling a cancelation could arise organically
This file contains 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
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