| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 import 'package:collection/collection.dart'; | 8 import 'package:collection/collection.dart'; |
| 9 | 9 |
| 10 import "cancelable_operation.dart"; | 10 import "cancelable_operation.dart"; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 /// ```dart | 346 /// ```dart |
| 347 /// final _stdinQueue = new StreamQueue(stdin); | 347 /// final _stdinQueue = new StreamQueue(stdin); |
| 348 /// | 348 /// |
| 349 /// /// Returns an operation that completes when the user sends a line to | 349 /// /// Returns an operation that completes when the user sends a line to |
| 350 /// /// standard input. | 350 /// /// standard input. |
| 351 /// /// | 351 /// /// |
| 352 /// /// If the operation is canceled, stops waiting for user input. | 352 /// /// If the operation is canceled, stops waiting for user input. |
| 353 /// CancelableOperation<String> nextStdinLine() => | 353 /// CancelableOperation<String> nextStdinLine() => |
| 354 /// _stdinQueue.cancelable((queue) => queue.next); | 354 /// _stdinQueue.cancelable((queue) => queue.next); |
| 355 /// ``` | 355 /// ``` |
| 356 CancelableOperation/*<S>*/ cancelable/*<S>*/( | 356 CancelableOperation<S> cancelable<S>( |
| 357 Future/*<S>*/ callback(StreamQueue<T> queue)) { | 357 Future<S> callback(StreamQueue<T> queue)) { |
| 358 var transaction = startTransaction(); | 358 var transaction = startTransaction(); |
| 359 var completer = new CancelableCompleter/*<S>*/(onCancel: () { | 359 var completer = new CancelableCompleter<S>(onCancel: () { |
| 360 transaction.reject(); | 360 transaction.reject(); |
| 361 }); | 361 }); |
| 362 | 362 |
| 363 var queue = transaction.newQueue(); | 363 var queue = transaction.newQueue(); |
| 364 completer.complete(callback(queue).whenComplete(() { | 364 completer.complete(callback(queue).whenComplete(() { |
| 365 if (!completer.isCanceled) transaction.commit(queue); | 365 if (!completer.isCanceled) transaction.commit(queue); |
| 366 })); | 366 })); |
| 367 | 367 |
| 368 return completer.operation; | 368 return completer.operation; |
| 369 } | 369 } |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 } | 979 } |
| 980 | 980 |
| 981 bool update(QueueList<Result<T>> events, bool isDone) { | 981 bool update(QueueList<Result<T>> events, bool isDone) { |
| 982 while (_eventsSent < events.length) { | 982 while (_eventsSent < events.length) { |
| 983 events[_eventsSent++].addTo(_controller); | 983 events[_eventsSent++].addTo(_controller); |
| 984 } | 984 } |
| 985 if (isDone && !_controller.isClosed) _controller.close(); | 985 if (isDone && !_controller.isClosed) _controller.close(); |
| 986 return false; | 986 return false; |
| 987 } | 987 } |
| 988 } | 988 } |
| OLD | NEW |