Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: sdk/lib/async/stream.dart

Issue 1415533015: If computation of Stream.periodic throws, forward the error to the stream. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Now ith actual change too. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/async/stream.dart
diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart
index 232d8db316b1e5c267fd4a822bf104995b3be0bc..7766c81a3b0a34fe880b97c6d4a00c779193239d 100644
--- a/sdk/lib/async/stream.dart
+++ b/sdk/lib/async/stream.dart
@@ -139,8 +139,6 @@ abstract class Stream<T> {
*/
factory Stream.periodic(Duration period,
[T computation(int computationCount)]) {
- if (computation == null) computation = ((i) => null);
-
Timer timer;
int computationCount = 0;
StreamController<T> controller;
@@ -149,7 +147,15 @@ abstract class Stream<T> {
void sendEvent() {
watch.reset();
- T data = computation(computationCount++);
+ T data;
+ if (computation != null) {
+ try {
+ data = computation(computationCount++);
+ } catch (e, s) {
+ controller.addError(e, s);
+ return;
+ }
+ }
controller.add(data);
}
@@ -1622,9 +1628,9 @@ abstract class StreamTransformer<S, T> {
* onDone: controller.close,
* cancelOnError: cancelOnError);
* },
- * onPause: () => subscription.pause(),
- * onResume: () => subscription.resume(),
- * onCancel: () => subscription.cancel(),
+ * onPause: () { subscription.pause(); },
+ * onResume: () { subscription.resume(); },
+ * onCancel: () { subscription.cancel(); },
* sync: true);
* return controller.stream.listen(null);
* });
« no previous file with comments | « no previous file | tests/lib/async/stream_periodic6_test.dart » ('j') | tests/lib/async/stream_periodic6_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698