blob: 8b05a45224f898a7977a8af9c85d4c4006bb929c [file] [log] [blame] [edit]
// Copyright (c) 2024, 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.
/// @assertion FutureOr<void> Function()? onCancel
/// The callback which is called when the stream is canceled.
///
/// May be set to `null`, in which case no callback will happen.
///
/// @description Checks that this callback is not called when the stream is
/// paused.
/// @author sgrekhov22@gmail.com
import "dart:async";
import "../../../Utils/expect.dart";
main() {
asyncStart();
var stream = Stream<int>.multi((controller) {
controller.onCancel = () {
Expect.fail("Unexpected onCancel");
};
controller.add(1);
controller.add(2);
controller.add(3);
});
listen(stream);
listen(stream);
Future.delayed(Duration(milliseconds: 200), asyncEnd);
}
void listen(Stream<int> stream) {
late StreamSubscription ss;
ss = stream.listen((v) {
if (v == 1) {
ss.pause();
}
});
}