Waiting for Futures raised by other Futures

你离开我真会死。 提交于 2019-12-01 22:06:42
Günter Zöchbauer

the code from How do I do this jquery pattern in dart? looks very similar to yours

For each entry of _db.keys() a future is added to an array and then waited for all of them being finished by Future.wait()

Not sure if this code works (see comments on the answer on the linked question)

void fnA() {
    fnB().then((_) {
        // Here, all 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) {
        // do something with data
        return data;
      }));
    }).then((_) => Future.wait(futures));
  });
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!