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

cancellation/abortion feature support #42

Open
weidonglian opened this issue May 5, 2021 · 1 comment
Open

cancellation/abortion feature support #42

weidonglian opened this issue May 5, 2021 · 1 comment

Comments

@weidonglian
Copy link

weidonglian commented May 5, 2021

I am digging into the library more and more and really appreciate and enjoy it!
One feature which is missing now is that how to cancel the chained pipeline.
Inside the pipeline (both in the promise callback and corresponding then-result-handler) we can call promise.set_exception or return cancel() to terminate the chained pipeline or stop() it which is really good.
How to abort or cancel from outside? i.e. in my app, I want to abort the pipeline or kill it during the shutdown, I want to quit as soon as possible.
Since continuable is preferred R-value, once we let the chained pipeline run, we have no reference or control over it.
My current solution is to pass a lambda (i.e. abortion/cancellation checker) in the callback and then-handlers, if it returns true, we will call cti::cancel(). However, the downside of this solution is that you have to call and check it in every handler and promise callback.

  1. Is there any plan or future support for passing this kinda abort/cancellation checker into the framework? then we do not need to proactively check it everywhere.
  2. Even better, we can pass in a cancellation/timeout/deadline context as context.Context in golang with support like below:
ctx, cancel := context.withContext(backgroundContext)
// later we can call `cancel` function to drop the whole pipeline. 
// timeout/deadline are just fancy interface to call this `cancel()` by the timer.
@Naios
Copy link
Owner

Naios commented Jun 16, 2021

I see that cancellation is one of the features that would improve this library significantly.
However, its implementation is not trivial since we would need to create another side channel to pass a possible cancellation upwards to the continuation chain. This creates a non-neglectable overhead, and therefore, the presence of this feature also affects users that don't use it.

A workaround to the not supported cancellation by continuable is to pass a cancellation callback to all functions that return a cancellable continuable or are executed in parallel with such. Therefore, the work could be canceled.

If you create a composition through when_all or when_seq it is sufficient to mark one result with canceled (work.set_canceled()) to not execute the following continuations.

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

No branches or pull requests

2 participants