我有一个长时间运行的任务,我想与 Future 异步运行,但我也希望它最终超时。在我看来,我的超时从未被调用 - 但也许我没有正确使用超时?
// do actual solution finding asychronously
Future populateFuture = new Future(() {
populateGrid(words, gridWidth, gridHeight);
});
populateFuture.timeout(const Duration(seconds: 3), onTimeout: () {
window.alert("Could not create a word search in a reasonable amount of time.");
});
// after being done, draw it if one was found
populateFuture.then((junk) {
wordSearchGrid.drawOnce();
});
这是在1.3.0-dev.4.1版本下也许我只是误解了如何使用超时