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"; |
11 import "result.dart"; | 11 import "result/result.dart"; |
12 import "subscription_stream.dart"; | 12 import "subscription_stream.dart"; |
13 import "stream_completer.dart"; | 13 import "stream_completer.dart"; |
14 import "stream_splitter.dart"; | 14 import "stream_splitter.dart"; |
15 | 15 |
16 /// An asynchronous pull-based interface for accessing stream events. | 16 /// An asynchronous pull-based interface for accessing stream events. |
17 /// | 17 /// |
18 /// Wraps a stream and makes individual events available on request. | 18 /// Wraps a stream and makes individual events available on request. |
19 /// | 19 /// |
20 /// You can request (and reserve) one or more events from the stream, | 20 /// You can request (and reserve) one or more events from the stream, |
21 /// and after all previous requests have been fulfilled, stream events | 21 /// and after all previous requests have been fulfilled, stream events |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 /// Request for a [StreamQueue.cancel] call. | 855 /// Request for a [StreamQueue.cancel] call. |
856 /// | 856 /// |
857 /// The request needs no events, it just waits in the request queue | 857 /// The request needs no events, it just waits in the request queue |
858 /// until all previous events are fulfilled, then it cancels the stream queue | 858 /// until all previous events are fulfilled, then it cancels the stream queue |
859 /// source subscription. | 859 /// source subscription. |
860 class _CancelRequest<T> implements _EventRequest<T> { | 860 class _CancelRequest<T> implements _EventRequest<T> { |
861 /// Completer for the future returned by the `cancel` call. | 861 /// Completer for the future returned by the `cancel` call. |
| 862 /// TODO(lrn); make this Completer<void> when that is implemented. |
862 final _completer = new Completer(); | 863 final _completer = new Completer(); |
863 | 864 |
864 /// | |
865 /// When the event is completed, it needs to cancel the active subscription | 865 /// When the event is completed, it needs to cancel the active subscription |
866 /// of the `StreamQueue` object, if any. | 866 /// of the `StreamQueue` object, if any. |
867 final StreamQueue _streamQueue; | 867 final StreamQueue _streamQueue; |
868 | 868 |
869 _CancelRequest(this._streamQueue); | 869 _CancelRequest(this._streamQueue); |
870 | 870 |
871 /// The future completed when the cancel request is completed. | 871 /// The future completed when the cancel request is completed. |
872 Future get future => _completer.future; | 872 Future get future => _completer.future; |
873 | 873 |
874 bool update(QueueList<Result<T>> events, bool isDone) { | 874 bool update(QueueList<Result<T>> events, bool isDone) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 971 } |
972 | 972 |
973 bool update(QueueList<Result<T>> events, bool isDone) { | 973 bool update(QueueList<Result<T>> events, bool isDone) { |
974 while (_eventsSent < events.length) { | 974 while (_eventsSent < events.length) { |
975 events[_eventsSent++].addTo(_controller); | 975 events[_eventsSent++].addTo(_controller); |
976 } | 976 } |
977 if (isDone && !_controller.isClosed) _controller.close(); | 977 if (isDone && !_controller.isClosed) _controller.close(); |
978 return false; | 978 return false; |
979 } | 979 } |
980 } | 980 } |
OLD | NEW |