If you get three different futures from three different servers, what order do you wait on?
what if you want to work on whatever results that finishes the first?
_Select(selector-expression)
works like _Accept
.
_Accept
works for callee-server_Select
works for caller-client with FutureUsage:
_Select(f1);
- Selector is select blocked until f1.available() == true
.f1()
is doing selection._Select(f1 || f2 && f3); === _Select(f1 || (f2 && f3));
f1
that become available or f2 && f3
that became available._Select(f1) or (_Select(f2) and _Select(f3))
_When(conditional) _Select(){
statement
} or
_When(conditional) _Select(f2){
statement
} and _When(conditional) _Select(f3){
statement
}
There is _Else
clause for non-blocking check.
_Select(selector){
}_When(condition) _Else{
}
_Else
must be the last clause of a select statement.
This may also result in a busy waiting.
Future_ISM<int> fi;
Future_ISM<double> fd;
struct Msg{int i, j;}; Future_ISM<Msg> fm;
struct Stop{}; Future_ISM<Stop> fs;
struct Cont{}; Future_ISM<Cont> fc;
_Task Worker{
void main (){
for(;;){
_Select(fi){cout << fi() << endl; fi.reset();}
and _Select(fd){cout << fd() << endl; fd. reset();}
and _Select(fm){
Msg m = fm();
cout << m.i << " " << m.j << endl;
fm.reset();
} or _Select(fs){
cout << "stop" << endl;
break;
}
fc.delivery((Cont){}); // synchronize;
}
}
};
int main(){
Worker worker;
for(int i = 0; i < 10; i++){
fi.delivery(i);
fd.delivery(i+2.5);
fm.delivery((Msg){i,2});
fc(); // wait until all 3 futures to be processed
fc.reset();
}
fs.delivery((Stop){});
}