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 /** | 5 /** |
6 * Support for asynchronous programming, | 6 * Support for asynchronous programming, |
7 * with classes such as Future and Stream. | 7 * with classes such as Future and Stream. |
8 * | 8 * |
9 * Understanding [Future]s and [Stream]s is a prerequisite for | 9 * Understanding [Future]s and [Stream]s is a prerequisite for |
10 * writing just about any Dart program. | 10 * writing just about any Dart program. |
(...skipping 25 matching lines...) Expand all Loading... |
36 * The value returned by the operation | 36 * The value returned by the operation |
37 * is passed into the callback function. | 37 * is passed into the callback function. |
38 * In this example, the `bind()` method returns the HttpServer | 38 * In this example, the `bind()` method returns the HttpServer |
39 * object. The callback function prints one of its properties. | 39 * object. The callback function prints one of its properties. |
40 * [Future.catchError] registers a callback function that | 40 * [Future.catchError] registers a callback function that |
41 * runs if an error occurs within the Future. | 41 * runs if an error occurs within the Future. |
42 * | 42 * |
43 * ## Stream | 43 * ## Stream |
44 * | 44 * |
45 * A Stream provides an asynchronous sequence of data. | 45 * A Stream provides an asynchronous sequence of data. |
46 * Examples of data sequences include user-generated events, | 46 * Examples of data sequences include individual events, like mouse clicks, |
47 * such as mouse clicks, and a stream of bytes read from a file. | 47 * or sequential chunks of larger data, like multiple byte lists with the |
| 48 * contents of a file |
| 49 * such as mouse clicks, and a stream of byte lists read from a file. |
48 * The following example opens a file for reading. | 50 * The following example opens a file for reading. |
49 * [Stream.listen] registers a callback function that runs | 51 * [Stream.listen] registers a callback function that runs |
50 * each time more data is available. | 52 * each time more data is available. |
51 * | 53 * |
52 * Stream<List<int>> stream = new File('quotes.txt').openRead(); | 54 * Stream<List<int>> stream = new File('quotes.txt').openRead(); |
53 * stream.transform(UTF8.decoder).listen(print); | 55 * stream.transform(UTF8.decoder).listen(print); |
54 * | 56 * |
55 * The stream emits a sequence of a list of bytes. | 57 * The stream emits a sequence of a list of bytes. |
56 * The program must interpret the bytes or handle the raw byte data. | 58 * The program must interpret the bytes or handle the raw byte data. |
57 * Here, the code uses a UTF8 decoder (provided in the `dart:convert` library) | 59 * Here, the code uses a UTF8 decoder (provided in the `dart:convert` library) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 part 'future.dart'; | 99 part 'future.dart'; |
98 part 'future_impl.dart'; | 100 part 'future_impl.dart'; |
99 part 'schedule_microtask.dart'; | 101 part 'schedule_microtask.dart'; |
100 part 'stream.dart'; | 102 part 'stream.dart'; |
101 part 'stream_controller.dart'; | 103 part 'stream_controller.dart'; |
102 part 'stream_impl.dart'; | 104 part 'stream_impl.dart'; |
103 part 'stream_pipe.dart'; | 105 part 'stream_pipe.dart'; |
104 part 'stream_transformers.dart'; | 106 part 'stream_transformers.dart'; |
105 part 'timer.dart'; | 107 part 'timer.dart'; |
106 part 'zone.dart'; | 108 part 'zone.dart'; |
OLD | NEW |