dart - Waiting for Futures raised by other Futures -


i'm using lawndart library access browser data, , want collect results of set of queries. here's thought should work:

  numberofrecordspersection(callback) {     var map = new map();      db_sections.keys().foreach((_key) {       db_sections.getbykey(_key).then((map _section) {         int count = _section.length;         map[_key] = count;       });     }).then(callback(map));   } 

however, when callback called, map still empty (it gets populated correctly, later, after futures have completed). assume problem futures created getbykey() calls not "captured by" futures created foreach() calls.

how can correct code capture result correctly?

the code how do jquery pattern in dart? looks similar yours

for each entry of _db.keys() future added array , waited of them being finished future.wait()

not sure if code works (see comments on answer on linked question)

void fna() {     fnb().then((_) {         // here, keys should have been loaded     }); }  future fnb() {   return _db.open().then((_) {     list<future> futures = [];     return _db.keys().foreach((string key_name) {        futures.add(_db.getbykey(key_name).then((string data) {         // data         return data;       }));     }).then((_) => future.wait(futures));   }); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -