blob: 22bdd3d2e375a2a49aec1df158fa5d33e259a055 [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 addOnExitListener(
/// SendPort responsePort, {
/// Object response
/// })
/// Asks the isolate to send response on responsePort when it terminates.
/// The isolate will send a response message on responsePort as the last
/// thing before it terminates. It will run no further code after the message
/// has been sent.
/// @description Check that several listeners can be added and each receive
/// given response when isolate terminates.
/// @author
import "dart:isolate";
import "dart:async";
import "../../../Utils/expect.dart";
import "IsolateUtil.dart";
test() async {
ErrorServer server = await ErrorServer.spawn(errorsAreFatal:false);
List<Object?> expectedResponses = [
null, null,
true, false,
0, 1, -1, 1024,
"a", "ABC",
1.1, 0.0, double.nan
ReceivePort onExit = new ReceivePort();
List<Future<dynamic>> actualResponses = [onExit.first];
for (Object? r in expectedResponses.skip(1)){
ReceivePort p = new ReceivePort();
server.isolate.addOnExitListener(p.sendPort, response:r);
Expect.listEquals(expectedResponses, await Future.wait(actualResponses));
main() {