| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Provides a Future which will be completed once the transaction has | 10 * Provides a Future which will be completed once the transaction has |
| 11 * completed. | 11 * completed. |
| 12 * | 12 * |
| 13 * The future will error if an error occurrs on the transaction or if the | 13 * The future will error if an error occurrs on the transaction or if the |
| 14 * transaction is aborted. | 14 * transaction is aborted. |
| 15 */ | 15 */ |
| 16 Future<Database> get completed { | 16 Future<Database> get completed { |
| 17 var completer = new Completer<Database>(); | 17 var completer = new Completer<Database>(); |
| 18 | 18 |
| 19 var errored = false; |
| 20 |
| 19 this.onComplete.first.then((_) { | 21 this.onComplete.first.then((_) { |
| 20 completer.complete(db); | 22 completer.complete(db); |
| 21 }); | 23 }); |
| 22 | 24 |
| 23 this.onError.first.then((e) { | 25 this.onError.first.then((e) { |
| 26 errored = true; |
| 24 completer.completeError(e); | 27 completer.completeError(e); |
| 25 }); | 28 }); |
| 26 | 29 |
| 27 this.onAbort.first.then((e) { | 30 this.onAbort.first.then((e) { |
| 28 completer.completeError(e); | 31 // Avoid completing twice if an error occurs. |
| 32 if (!errored) { |
| 33 completer.completeError(e); |
| 34 } |
| 29 }); | 35 }); |
| 30 | 36 |
| 31 return completer.future; | 37 return completer.future; |
| 32 } | 38 } |
| 33 | 39 |
| 34 $!MEMBERS | 40 $!MEMBERS |
| 35 } | 41 } |
| OLD | NEW |