dart - Execute Futures until a parameter becomes true -


i launch request server future "requestserver". poll system specific value (passed false true, when request done) , return when finished.

code that, "while" synchronous , "checkoperation" asynchronous?

return requestserver().then((operation) {   var done = false;   while (done)     return checkoperation(operation).then((result) {       done = (result == true);     });     sleep(10);   } }); 

any ideas ?

i guess not want far know there no way block execution have use callbacks.

void main(list<string> args) {    // polling   new timer.periodic(new duration(microseconds: 100), (t) {     if(isdone) {       t.cancel();       somecallback();     }   });    // set isdone true in future   new future.delayed(new duration(seconds: 10), () => isdone = true); }  bool isdone = false;  void somecallback() {   print('isdone: $isdone');   // continue processing } 

you can of course pass callback parameter instead of hardcode it, because functions first class members in dart.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -