| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 8 | 8 |
| 9 @DomName('IDBObjectStore.add') | 9 @DomName('IDBObjectStore.add') |
| 10 Future add(value, [key]) { | 10 Future add(value, [key]) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 $!MEMBERS | 140 $!MEMBERS |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Helper for iterating over cursors in a request. | 143 * Helper for iterating over cursors in a request. |
| 144 */ | 144 */ |
| 145 static Stream<Cursor> _cursorStreamFromResult(Request request, | 145 static Stream<Cursor> _cursorStreamFromResult(Request request, |
| 146 bool autoAdvance) { | 146 bool autoAdvance) { |
| 147 // TODO: need to guarantee that the controller provides the values | 147 // TODO: need to guarantee that the controller provides the values |
| 148 // immediately as waiting until the next tick will cause the transaction to | 148 // immediately as waiting until the next tick will cause the transaction to |
| 149 // close. | 149 // close. |
| 150 var controller = new StreamController(); | 150 var controller = new StreamController(sync: true); |
| 151 | 151 |
| 152 request.onError.listen((e) { | 152 request.onError.listen((e) { |
| 153 //TODO: Report stacktrace once issue 4061 is resolved. | 153 //TODO: Report stacktrace once issue 4061 is resolved. |
| 154 controller.addError(e); | 154 controller.addError(e); |
| 155 }); | 155 }); |
| 156 | 156 |
| 157 request.onSuccess.listen((e) { | 157 request.onSuccess.listen((e) { |
| 158 Cursor cursor = request.result; | 158 Cursor cursor = request.result; |
| 159 if (cursor == null) { | 159 if (cursor == null) { |
| 160 controller.close(); | 160 controller.close(); |
| 161 } else { | 161 } else { |
| 162 controller.add(cursor); | 162 controller.add(cursor); |
| 163 if (autoAdvance == true && controller.hasListener) { | 163 if (autoAdvance == true && controller.hasListener) { |
| 164 cursor.next(); | 164 cursor.next(); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 }); | 167 }); |
| 168 return controller.stream; | 168 return controller.stream; |
| 169 } | 169 } |
| 170 } | 170 } |
| OLD | NEW |