Skip to content

Commit

Permalink
feat: sort_candidates is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager committed Feb 6, 2024
1 parent a6d2138 commit d76a865
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ pub trait DependencyProvider<VS: VersionSet, N: PackageName = String>: Sized {
/// Sort the specified solvables based on which solvable to try first. The solver will
/// iteratively try to select the highest version. If a conflict is found with the highest
/// version the next version is tried. This continues until a solution is found.
fn sort_candidates(&self, solver: &SolverCache<VS, N, Self>, solvables: &mut [SolvableId]);
///
/// # Async
///
/// The returned future will be awaited by a tokio runtime blocking the main thread. You are
/// free to use other runtimes in your implementation, as long as the runtime-specific code runs
/// in threads controlled by that runtime (and _not_ in the main thread). For instance, you can
/// use `async_std::task::spawn` to spawn a new task, use `async_std::io` inside the task to
/// retrieve necessary information from the network, and `await` the returned task handle.

Check warning on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/resolvo/resolvo/src/lib.rs

#[allow(async_fn_in_trait)]
async fn sort_candidates(&self, solver: &SolverCache<VS, N, Self>, solvables: &mut [SolvableId]);

/// Obtains a list of solvables that should be considered when a package with the given name is
/// requested.
Expand Down
2 changes: 1 addition & 1 deletion src/solver/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<VS: VersionSet, N: PackageName, D: DependencyProvider<VS, N>> SolverCache<V
// Sort all the candidates in order in which they should be tried by the solver.

Check warning on line 211 in src/solver/cache.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/resolvo/resolvo/src/solver/cache.rs
let mut sorted_candidates = Vec::new();
sorted_candidates.extend_from_slice(matching_candidates);
self.provider.sort_candidates(self, &mut sorted_candidates);
self.provider.sort_candidates(self, &mut sorted_candidates).await;

// If we have a solvable that we favor, we sort that to the front. This ensures
// that the version that is favored is picked first.
Expand Down
2 changes: 1 addition & 1 deletion tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl DependencyProvider<Range<Pack>> for BundleBoxProvider {
self.pool.clone()
}

fn sort_candidates(
async fn sort_candidates(
&self,
_solver: &SolverCache<Range<Pack>, String, Self>,
solvables: &mut [SolvableId],
Expand Down

0 comments on commit d76a865

Please sign in to comment.