blob: 030b72912d1ba74d333d84b2534e1015fd2884b5 [file] [log] [blame]
// Copyright (c) 2017, 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 void removeOnExitListener(
/// SendPort responsePort
/// )
/// Stop listening on exit messages from the isolate.
/// If a call has previously been made to addOnExitListener with the same
/// send-port, this will unregister the port, and it will no longer receive
/// a message when the isolate terminates. A response may still be sent until
/// this operation is fully processed by the isolate.
///
/// @description Check that given port does not receive events after call
/// to removeOnExitListener().
///
/// @author a.semenov@unipro.ru
import "dart:isolate";
import "dart:async";
import "../../../Utils/expect.dart";
import "IsolateUtil.dart";
test() async {
// setup
ReceivePort receivePort = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Future onExitFuture = onExit.first;
EchoServer server = await EchoServer.spawn(receivePort.sendPort);
server.isolate.addOnExitListener(onExit.sendPort);
// do something
server.send("hello");
await receivePort.first;
server.isolate.removeOnExitListener(onExit.sendPort);
await server.stop();
onExitFuture = onExitFuture.timeout(new Duration(milliseconds: 200),
onTimeout: () => "timeout");
Expect.equals("timeout", await onExitFuture);
// clean up
onExit.close();
asyncEnd();
}
main() {
asyncStart();
test();
}