Skip to content

promise::all(...) cannot resolve to native vector #23

@geiseri

Description

@geiseri

Greetings, I have the following code:

std::vector<Promise> promise_list = { 
  promise::resolve<float>(10),
  promise::resolve<float>(11),
};

all(promise_list).then([](const std::vector<float> &vals){
    /* code here for all promise objects are resolved */
}).fail([](){
    /* code here for one of the promise objects is rejected */
});

This compiles but bails with a bad any_cast execption. The following though works:

std::vector<Promise> promise_list = { 
promise::resolve<float>(10),
promise::resolve<float>(11),
};

all(promise_list).then([](const std::vector<any> &vals){
   std::vector<float> res{};
   std::transform(vals.begin(), vals.end(), std::back_inserter(res),
                           [](const promise::any &r) { return r.cast<float>(); });
  return res;
}).then([](const std::vector<float> &vals){
    /* code here for all promise objects are resolved as floats */
}).fail([](){
    /* code here for one of the promise objects is rejected */
});

I am wondering if you can use the container std::vector<T>::value_type for the cast from the promise into the function. I am not sure if this would break other stuff though since it would need to happen after resolution. This would also break instances where you have multiple types returned by the promises. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions