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

feat: allow cancelling the solving process #20

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

aochagavia
Copy link
Contributor

Introduces a should_cancel_with_value method in DependencyProvider,
that returns an Option<Box<dyn Any>>. This method is called at the
beginning of each unit propagation round and before potentially blocking
operations (like [Self::get_dependencies] and [Self::get_candidates]).

If should_cancel_with_value returns Some(...),
propagation is interrupted and the solver returns
Err(UnsolvableOrCancelled::Cancelled(...)), bubbling up the value to
the library user (this way you can handle any additional details
surrounding the cancellation outside of the solver).

Closes #8.

Remarks

  • SolverCache::provider is now pub(crate). Is that all right?
  • The current design requires implementors of DependencyProvider to use interior mutability to track cancellation. I think that's reasonable, because otherwise we would need to take &mut self in all of DependencyProvider methods, but I'm mentioning it here in case anyone has a different opinion.

Introduces a `should_cancel_with_value` method in `DependencyProvider`,
that returns an `Option<Box<dyn Any>>`. This method is called at the
beginning of each unit propagation round and before potentially blocking
operations (like [Self::get_dependencies] and [Self::get_candidates]).

If `should_cancel_with_value` returns `Some(...)`,
propagation is interrupted and the solver returns
`Err(UnsolvableOrCancelled::Cancelled(...))`, bubbling up the value to
the library user (this way you can handle any additional details
surrounding the cancellation outside of the solver).
@wolfv wolfv merged commit 7c1fa14 into mamba-org:main Jan 25, 2024
3 checks passed
@aochagavia aochagavia deleted the cancellation branch January 25, 2024 10:36
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

Successfully merging this pull request may close these issues.

Add a "timeout" parameter or other stop conditions
3 participants