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 dart.async; | 5 part of dart.async; |
6 | 6 |
7 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
8 // Core Stream types | 8 // Core Stream types |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 | 10 |
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1371 * When you listen on a [Stream] using [Stream.listen], | 1371 * When you listen on a [Stream] using [Stream.listen], |
1372 * a [StreamSubscription] object is returned. | 1372 * a [StreamSubscription] object is returned. |
1373 * | 1373 * |
1374 * The subscription provides events to the listener, | 1374 * The subscription provides events to the listener, |
1375 * and holds the callbacks used to handle the events. | 1375 * and holds the callbacks used to handle the events. |
1376 * The subscription can also be used to unsubscribe from the events, | 1376 * The subscription can also be used to unsubscribe from the events, |
1377 * or to temporarily pause the events from the stream. | 1377 * or to temporarily pause the events from the stream. |
1378 */ | 1378 */ |
1379 abstract class StreamSubscription<T> { | 1379 abstract class StreamSubscription<T> { |
1380 /** | 1380 /** |
1381 * Cancels this subscription. It will no longer receive events. | 1381 * Cancels this subscription. |
1382 * | 1382 * |
1383 * May return a future which completes when the stream is done cleaning up. | 1383 * After this call it does no longer receive events. However, the cleanup of |
Lasse Reichstein Nielsen
2016/02/09 16:34:53
"After this call returns, the subscription no long
floitsch
2016/02/09 17:26:51
Done.
| |
1384 * This can be used if the stream needs to release some resources | 1384 * the stream might not be finished yet. |
1385 * that are needed for a following operation, | |
1386 * for example a file being read, that should be deleted afterwards. | |
1387 * In that case, the file may not be able to be deleted successfully | |
1388 * until the returned future has completed. | |
1389 * | 1385 * |
1390 * The future will be completed with a `null` value. | 1386 * Returns `null` if the cleanup is finished, or a future otherwise. |
1387 * In the latter case, the future is completed once the stream has finished | |
1388 * its cleanup. | |
Lasse Reichstein Nielsen
2016/02/09 16:34:53
I would focus on returning a future - we have many
floitsch
2016/02/09 17:26:51
Done.
| |
1389 * | |
1390 * Typically, futures are returned when the stream needs to release resources. | |
1391 * For example, a stream might need to close an open file (as an asynchronous | |
1392 * operation). If the listener wants to delete the file after having | |
1393 * canceled the subscription, it must wait for the cleanup future to complete. | |
1394 * | |
1395 * A returned future completes with a `null` value. | |
1391 * If the cleanup throws, which it really shouldn't, the returned future | 1396 * If the cleanup throws, which it really shouldn't, the returned future |
1392 * will be completed with that error. | 1397 * completes with that error. |
1393 * | |
1394 * Returns `null` if there is no need to wait. | |
1395 */ | 1398 */ |
1396 Future cancel(); | 1399 Future cancel(); |
1397 | 1400 |
1398 /** | 1401 /** |
1399 * Set or override the data event handler of this subscription. | 1402 * Set or override the data event handler of this subscription. |
1400 * | 1403 * |
1401 * This method overrides the handler that has been set at the invocation of | 1404 * This method overrides the handler that has been set at the invocation of |
1402 * [Stream.listen]. | 1405 * [Stream.listen]. |
1403 */ | 1406 */ |
1404 void onData(void handleData(T data)); | 1407 void onData(void handleData(T data)); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1796 class _ControllerEventSinkWrapper<T> implements EventSink<T> { | 1799 class _ControllerEventSinkWrapper<T> implements EventSink<T> { |
1797 EventSink _sink; | 1800 EventSink _sink; |
1798 _ControllerEventSinkWrapper(this._sink); | 1801 _ControllerEventSinkWrapper(this._sink); |
1799 | 1802 |
1800 void add(T data) { _sink.add(data); } | 1803 void add(T data) { _sink.add(data); } |
1801 void addError(error, [StackTrace stackTrace]) { | 1804 void addError(error, [StackTrace stackTrace]) { |
1802 _sink.addError(error, stackTrace); | 1805 _sink.addError(error, stackTrace); |
1803 } | 1806 } |
1804 void close() { _sink.close(); } | 1807 void close() { _sink.close(); } |
1805 } | 1808 } |
OLD | NEW |