a957c4351a
Change-Id: Icadb9edfe2ef40aff3808295685f961897d63c9a Reviewed-on: https://dart-review.googlesource.com/c/86181 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
47 lines
1.2 KiB
Dart
47 lines
1.2 KiB
Dart
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Test that stream cancellation is checked immediately after delivering the
|
|
// event, and before continuing after the yield.
|
|
|
|
import "dart:async";
|
|
import "package:expect/expect.dart";
|
|
import "package:async_helper/async_helper.dart";
|
|
|
|
main() async {
|
|
asyncStart();
|
|
var log = [];
|
|
Stream<int> f() async* {
|
|
try {
|
|
log.add("-1");
|
|
yield 1;
|
|
log.add("-2");
|
|
yield 2;
|
|
} finally {
|
|
log.add("x");
|
|
}
|
|
}
|
|
|
|
var completer = Completer();
|
|
var s;
|
|
s = f().listen((e) {
|
|
log.add("+$e");
|
|
// The `cancel` operation makes all `yield` operations act as returns.
|
|
// It should make the `finally` block in `f` log an "x",
|
|
// and nothing else.
|
|
completer.complete(s.cancel());
|
|
}, onError: (e) {
|
|
// Should never be reached, but if it does, we'll make the await
|
|
// below terminate.
|
|
completer.complete(new Future.sync(() {
|
|
Expect.fail("$e");
|
|
}));
|
|
}, onDone: () {
|
|
completer.complete(null);
|
|
});
|
|
await completer.future;
|
|
Expect.listEquals(["-1", "+1", "x"], log, "cancel");
|
|
asyncEnd();
|
|
}
|