Should long-running parsers check for task cancellation? #221
tgrapperon
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
@tgrapperon Interesting find! It does sound like calling |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
While I was toying with Parsing and the new
Regex
from Swift 5.7, it occurred to me that a few matching commands ofRegex
are throwing if matching is aborted (it returnsnil
when it fails). Looking at SE-0350, it corresponds to cases where the parentTask
is canceled.Since parsers are already throwing, should we implement the same behavior with potentially long-running parsers like
Many
orOneOf
for example?For example, if we make
Regex
aParser
(we could also wrap it in some type if needed):This parser will throw if the parent
Task
is aborted. Because the error shouldn't be aParsingError
, we can directly throwRegex
's own error. We could probably do the same with other parsers likeMany
.There are probably super interesting bridges to draw between
Parsing
andRegex
, and it probably doesn't stop there, but the question about checking task cancellation in parsers is orthogonal.Should we go on with it? Should we only perform the checks for a selected set of candidates?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions