Use then-combine for Two Independent Futures

Open Beginner friendly
#4,388 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Domain
backend, database

Research direction

Start with blaze.async.comp/then-combine (added with #4384) and the four call sites listed: resource_cache.clj (merge-futures), token_token.clj and token_quantity.clj (-compile-value), and value_set/expand.clj (expand-compose*). Replace each two-future ac/all-of with then-combine, watching the swapped prefix-with argument order in token_quantity.clj. Leave validate_code.clj and any three-or-more-future all-of untouched. Done when the four sites compile and their existing tests pass.

Written by the indexing model from the issue text.

Description

module:db module:terminology-service-local refactoring

blaze.async.comp/then-combine (introduced together with #4384) combines two independent CompletableFutures into one result. Several places still wait on exactly two independent futures with ac/all-of and join both afterwards. Replace them with then-combine:

  • modules/db/src/blaze/db/resource_cache.clj merge-futures → (ac/then-combine futures-1 futures-2 merge)
  • modules/db/src/blaze/db/impl/search_param/composite/token_token.clj -compile-value → (ac/then-combine f1 f2 bs/concat)
  • modules/db/src/blaze/db/impl/search_param/composite/token_quantity.clj -compile-value → (ac/then-combine f1 f2 (fn [v1 v2] (prefix-with v2 v1))) (note the swapped argument order of prefix-with)
  • modules/terminology-service-local/src/blaze/terminology_service/local/value_set/expand.clj expand-compose* → (ac/then-combine includes excludes (fn [includes excludes] ...))

Not in scope: all-of calls over three or more or a variable number of futures, and validate_code.clj, where the excludes lookup intentionally runs only after the includes succeeded and its failure is the success path.

Dominant language
Clojure
Stars
230
Forks
27
Avg merge
9h 20m
Merged PRs (30d)
149

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from samply/blaze

All issues in samply/blaze

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.