completed 属性

Future<Database> completed

提供一旦事务完成就会完成的 Future。

如果事务发生错误或事务被中止,Future 将会出错。

实现

Future<Database> get completed {
  var completer = new Completer<Database>();

  this.onComplete.first.then((_) {
    completer.complete(db);
  });

  this.onError.first.then((e) {
    completer.completeError(e);
  });

  this.onAbort.first.then((e) {
    // Avoid completing twice if an error occurs.
    if (!completer.isCompleted) {
      completer.completeError(e);
    }
  });

  return completer.future;
}