www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Array of Template instantiations

reply Alex <martin mab-on.net> writes:
Hi,

i don't even know if the subject makes any sense :)
What i want to achieve is: instead of making:

auto v_a = async( &load , queryA );
auto v_b = async( &load , queryB );
auto v_c = async( &load , queryC );
( async is a function from vibe and returns a "Future" - see http://vibed.org/api/vibe.core.concurrency/async for the async ) i want to something like this:
WHAT_TYPE[] futures;
futures ~= async( &load , queryA );
futures ~= async( &load , queryB );
futures ~= async( &load , queryC );
And then collect the results somwhere later like:
foreach(WHAT_TYPE future ; futures)
{
  writeln( future.getResult() );
}
The Problem is, i dont know what type WHAT_TYPE is / i don´t know how to build a loopable something of futures.
Jul 20
parent reply Alex <martin mab-on.net> writes:
On Thursday, 20 July 2017 at 12:33:43 UTC, Alex wrote:
 The Problem is, i dont know what type WHAT_TYPE is / i don´t 
 know how to build a loopable something of futures.
Ok, i think i understood now. my function `load` returns `KpiResponseEntity` so
Future!(KpiResponseEntity)[] futures;
seems to work
Jul 20
parent Meta <jared771 gmail.com> writes:
On Thursday, 20 July 2017 at 13:11:56 UTC, Alex wrote:
 On Thursday, 20 July 2017 at 12:33:43 UTC, Alex wrote:
 The Problem is, i dont know what type WHAT_TYPE is / i don´t 
 know how to build a loopable something of futures.
Ok, i think i understood now. my function `load` returns `KpiResponseEntity` so
Future!(KpiResponseEntity)[] futures;
seems to work
To get the type you can also use `typeof`. alias ResponseType = typeof(async(&load , queryA )); ResponseType[] futures; futures ~= async( &load , queryA ); futures ~= async( &load , queryB ); futures ~= async( &load , queryC );
Jul 20