I am trying to make non blocking web requests to a web service.
vibe.core.concurrency.Future!(UserData)[] futurelist;
// I will make http requests in for loop and push them to
futureList
foreach( elem; elemList )
{
// In makeWebRequest I make the httprequest, parse json
and push to my UserData
auto future = vibe.core.concurrency.async(
&elem.makeWebRequest );
futurelist ~= future;
}
// I want to do call ProcessResponceData for each future which is
ready.
while ( futurelist.length > 0 )
{
futurelist.filter!(a => a.ready()).each!(a=>
ProcessResponceData(a.getResult()));
//!!!!! Here is my problem
//!!!!! I want to remove the futures which are already
processed.
futurelist = futurelist.filter!(a => !a.ready()).array;
sleep(10.msecs);
}
I am having troubles while trying to remove the future which I
already processed.
futurelist = futurelist.filter!(a => !a.ready()).array; results
with:
/usr/local/bin/../import/std/array.d(2716,20): Error: can't have
array of nothrow @safe void()
/usr/local/bin/../import/std/array.d(2782,46): Error: can't have
array of inout nothrow @safe void()
/usr/local/bin/../import/std/array.d(3158,1): Error: template
instance std.array.Appender!(Future!(UserData)[]) error
instantiating
/usr/local/bin/../import/std/array.d(133,32): instantiated
from here: appender!(Future!(UserData)[])
futurelist = futurelist.filter!(a => !a.ready()); results with:
Error: cannot implicitly convert expression (filter(futurelist))
of type FilterResult!(__lambda5, Future!(UserData)[]) to
Future!(AnalyzeData)[]
Do you have any suggestion or workaround for my case?
What lesson I should learn from this case? Do you guys have any
idea why I am getting those compile errors?
Thanks
Erdem