[SERVER-53558] Make variadic whenAny implementation Created: 04/Jan/21  Updated: 29/Oct/23  Resolved: 18/Feb/21

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 5.0.0

Type: New Feature Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: Tyler Seip (Inactive)
Resolution: Fixed Votes: 0
Labels: servicearch-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2021-02-08, Service Arch 2021-02-22
Participants:

 Description   

whenAny is a function that takes in a vector of futures and returns a future that is resolved as soon as one of its inputs resolves. Because it takes a vector, users sometimes have to first construct a vector prior to using the function, which causes additional lines of code and also can be a hassle since the vector will likely contain ExecutorFutures, which are not copyable and so an initializer list cannot be used for vector construction (and leads to complicated compiler errors).

So currently you have to write something like:

// Does not compile:
// auto futures = {std::move(deadlineReachedFuture), std::move(someOtherFuture)};
// Does not compile for same reason:
//whenAny({std::move(deadlineReachedFuture), std::move(someOtherFuture)}).thenRunOn(executor).then(...);
 
std::vector<ExecutorFuture<void>> futures;
futures.emplace_back(std::move(deadlineReachedFuture));
futures.emplace_back(std::move(someOtherFuture));
whenAny(futures).thenRunOn(executor).then(...);

I think it would be worth making a variadic version of whenAny, so that you could instead do:

whenAny(std::move(deadlineReachedFuture), std::move(someOtherFuture))
    .thenRunOn(executor)
    .then(...);

Since a two-future usage of whenAny seems like it will be a common case (especially with deadlines), we could also choose to just have a single special case that just takes two parameters. I think if we chose the latter, however, it might make sense to make it something different entirely and have it support different input types for the different futures.



 Comments   
Comment by Githook User [ 18/Feb/21 ]

Author:

{'name': 'Tyler Seip', 'email': 'Tyler.Seip@mongodb.com', 'username': 'tseip-mongo'}

Message: SERVER-53558: Create variadic template implementations of when* future utilities
Branch: master
https://github.com/mongodb/mongo/commit/25818a31c7d8209aa8ae22a536f94725aa7fa21e

Generated at Thu Feb 08 05:31:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.