Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Why aren't cancellations propagated by composite futures? #333

Open
zah opened this issue Dec 7, 2022 · 0 comments
Open

[RFC] Why aren't cancellations propagated by composite futures? #333

zah opened this issue Dec 7, 2022 · 0 comments

Comments

@zah
Copy link
Contributor

zah commented Dec 7, 2022

Pretty much all composite futures in Chronos do not propagate cancellations. For example, here is what the documentation is saying about allFutures:

  ## Returns a future which will complete only when all futures in ``futs``
  ## will be completed, failed or canceled.
  ##
  ## If the argument is empty, the returned future COMPLETES immediately.
  ##
  ## On cancel all the awaited futures ``futs`` WILL NOT BE cancelled.

The treatment is similar for and, or, all, race.

What's the rationale behind this design choice? My expectation is that composite futures should propagate cancellation. For example, imagine I have the following async proc:

proc startMultiHourWorkflow() {.async.} =
  let job1 = startMultiHourJob()
  let job2 = startAnotherMultiHourJob()
  await allFutures([job1, job2])
  ...

In my application, I'm likely to have the following code:

app.workflowFut = startMultiHourWorkflow()
...
app.onSomeEvent do:
  app.workflowFut.cancel()

Naturally, I expect cancelling workflowFut to immediately stop any remaining work of "job1" and "job2" that may take another several hours to complete. Instead, Chronos will let them run to completion unless I explicitly write cancellation propagation code in my startMultiHourWorkflow proc, which strikes me as the wrong default (not wanting the cancellation to be propagated should be a rare and unusual use case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant