Future readData() {
var completer = new Completer();
print("querying");
pool.query('select p.id, p.name, p.age, t.name, t.species '
'from people p '
'left join pets t on t.owner_id = p.id').then((result) {
print("got results");
for (var row in result) {
if (row[3] == null) {
print("ID: ${row[0]}, Name: ${row[1]}, Age: ${row[2]}, No Pets");
} else {
print("ID: ${row[0]}, Name: ${row[1]}, Age: ${row[2]}, Pet Name: ${row[3]}, Pet Species ${row[4]}");
}
}
completer.complete(null);
});
return completer.future;
}
以上是取自github SQLJocky Connector的示例代码
如果可能的话,我希望有人向我解释一下,为什么在池之外创建了完成器对象的函数是这样的.查询然后调用一个函数Completer.Complete(NULL).
简而言之,在打印执行后,我无法理解该部分.
Note:Kindly if possible I would also like to know how is future and Completer used for practical purpose both for DB and non DB operations.个
我浏览了以下链接: Google groups discussion on Future and Completer个
以及api参考文档,如下所示