Chromium Code Reviews| 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 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1331 * [futureValue]. | 1331 * [futureValue]. |
| 1332 */ | 1332 */ |
| 1333 Future asFuture([var futureValue]); | 1333 Future asFuture([var futureValue]); |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 | 1336 |
| 1337 /** | 1337 /** |
| 1338 * An interface that abstracts creation or handling of [Stream] events. | 1338 * An interface that abstracts creation or handling of [Stream] events. |
| 1339 */ | 1339 */ |
| 1340 abstract class EventSink<T> implements Sink<T> { | 1340 abstract class EventSink<T> implements Sink<T> { |
| 1341 /** Create a data event */ | 1341 /** Create a data event on the stream. */ |
|
Anders Johnsen
2014/06/02 10:18:08
Send a ...? (and below)
Lasse Reichstein Nielsen
2014/06/02 10:52:53
Done.
| |
| 1342 void add(T event); | 1342 void add(T event); |
| 1343 /** Create an async error. */ | 1343 /** Create an async error on the stream. */ |
| 1344 void addError(errorEvent, [StackTrace stackTrace]); | 1344 void addError(errorEvent, [StackTrace stackTrace]); |
| 1345 /** Request a stream to close. */ | 1345 /** Request a stream to close. This should also create a done event.*/ |
| 1346 void close(); | 1346 void close(); |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 | 1349 |
| 1350 /** [Stream] wrapper that only exposes the [Stream] interface. */ | 1350 /** [Stream] wrapper that only exposes the [Stream] interface. */ |
| 1351 class StreamView<T> extends Stream<T> { | 1351 class StreamView<T> extends Stream<T> { |
| 1352 Stream<T> _stream; | 1352 Stream<T> _stream; |
| 1353 | 1353 |
| 1354 StreamView(this._stream); | 1354 StreamView(this._stream); |
| 1355 | 1355 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1380 /** | 1380 /** |
| 1381 * Consumes the elements of [stream]. | 1381 * Consumes the elements of [stream]. |
| 1382 * | 1382 * |
| 1383 * Listens on [stream] and does something for each event. | 1383 * Listens on [stream] and does something for each event. |
| 1384 * | 1384 * |
| 1385 * The consumer may stop listening after an error, or it may consume | 1385 * The consumer may stop listening after an error, or it may consume |
| 1386 * all the errors and only stop at a done event. | 1386 * all the errors and only stop at a done event. |
| 1387 */ | 1387 */ |
| 1388 Future addStream(Stream<S> stream); | 1388 Future addStream(Stream<S> stream); |
| 1389 | 1389 |
| 1390 /** | |
| 1391 * Tell the consumer that no futher streams will be added. | |
| 1392 * | |
| 1393 * Returns a future that is completed when the consumer is done handling | |
| 1394 * events. | |
| 1395 */ | |
| 1390 Future close(); | 1396 Future close(); |
| 1391 } | 1397 } |
| 1392 | 1398 |
| 1393 | 1399 |
| 1394 /** | 1400 /** |
| 1395 * A [StreamSink] unifies the asynchronous methods from [StreamConsumer] and | 1401 * A [StreamSink] unifies the asynchronous methods from [StreamConsumer] and |
| 1396 * the synchronous methods from [EventSink]. | 1402 * the synchronous methods from [EventSink]. |
| 1397 * | 1403 * |
| 1398 * The [EventSink] methods can't be used while the [addStream] is called. | 1404 * The [EventSink] methods can't be used while the [addStream] is called. |
| 1399 * As soon as the [addStream]'s [Future] completes with a value, the | 1405 * As soon as the [addStream]'s [Future] completes with a value, the |
| 1400 * [EventSink] methods can be used again. | 1406 * [EventSink] methods can be used again. |
| 1401 * | 1407 * |
| 1402 * If [addStream] is called after any of the [EventSink] methods, it'll | 1408 * If [addStream] is called after any of the [EventSink] methods, it'll |
| 1403 * be delayed until the underlying system has consumed the data added by the | 1409 * be delayed until the underlying system has consumed the data added by the |
| 1404 * [EventSink] methods. | 1410 * [EventSink] methods. |
| 1405 * | 1411 * |
| 1406 * When [EventSink] methods are used, the [done] [Future] can be used to | 1412 * When [EventSink] methods are used, the [done] [Future] can be used to |
| 1407 * catch any errors. | 1413 * catch any errors. |
| 1408 * | 1414 * |
| 1409 * When [close] is called, it will return the [done] [Future]. | 1415 * When [close] is called, it will return the [done] [Future]. |
| 1410 */ | 1416 */ |
| 1411 abstract class StreamSink<S> implements StreamConsumer<S>, EventSink<S> { | 1417 abstract class StreamSink<S> implements StreamConsumer<S>, EventSink<S> { |
| 1412 /** | 1418 /** |
| 1413 * Close the [StreamSink]. It'll return the [done] Future. | 1419 * As [EventSink.close], but also returns a future. |
| 1420 * | |
| 1421 * Returns a future which is completed when the close operation is complete. | |
| 1422 * If closing can fail for a particular `StreamSink`, the future will then | |
| 1423 * contain the error. | |
| 1414 */ | 1424 */ |
| 1415 Future close(); | 1425 Future close(); |
| 1416 | 1426 |
| 1417 /** | 1427 /** |
| 1418 * The [done] Future completes with the same values as [close], except | 1428 * Return a future which is completed when the [StreamSink] is cloed. |
|
Anders Johnsen
2014/06/02 10:18:08
cloed -> closed
Lasse Reichstein Nielsen
2014/06/02 10:52:53
Reworded entire comment.
| |
| 1419 * for the following case: | |
| 1420 * | 1429 * |
| 1421 * * The synchronous methods of [EventSink] were called, resulting in an | 1430 * If adding events using [add] and [addError] can fail, the [done] future |
| 1422 * error. If there is no active future (like from an addStream call), the | 1431 * will then contain the error. |
|
Anders Johnsen
2014/06/02 10:18:08
contain -> complete with
| |
| 1423 * [done] future will complete with that error | 1432 * |
| 1433 * If [close] is called, the returned future will complete with the same | |
| 1434 * result as the future returned by `close`. | |
|
Anders Johnsen
2014/06/02 10:18:08
the same result -> the same future (too complex to
| |
| 1424 */ | 1435 */ |
| 1425 Future get done; | 1436 Future get done; |
| 1426 } | 1437 } |
| 1427 | 1438 |
| 1428 | 1439 |
| 1429 /** | 1440 /** |
| 1430 * The target of a [Stream.transform] call. | 1441 * The target of a [Stream.transform] call. |
| 1431 * | 1442 * |
| 1432 * The [Stream.transform] call will pass itself to this object and then return | 1443 * The [Stream.transform] call will pass itself to this object and then return |
| 1433 * the resulting stream. | 1444 * the resulting stream. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1583 class _ControllerEventSinkWrapper<T> implements EventSink<T> { | 1594 class _ControllerEventSinkWrapper<T> implements EventSink<T> { |
| 1584 EventSink _sink; | 1595 EventSink _sink; |
| 1585 _ControllerEventSinkWrapper(this._sink); | 1596 _ControllerEventSinkWrapper(this._sink); |
| 1586 | 1597 |
| 1587 void add(T data) { _sink.add(data); } | 1598 void add(T data) { _sink.add(data); } |
| 1588 void addError(error, [StackTrace stackTrace]) { | 1599 void addError(error, [StackTrace stackTrace]) { |
| 1589 _sink.addError(error, stackTrace); | 1600 _sink.addError(error, stackTrace); |
| 1590 } | 1601 } |
| 1591 void close() { _sink.close(); } | 1602 void close() { _sink.close(); } |
| 1592 } | 1603 } |
| OLD | NEW |