blob: 9ee7666c336e47815046a84b171f78e661d64a8f [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 Capability pause([
/// Capability resumeCapability
/// ])
/// Requests the isolate to pause.
/// When the isolate receives the pause command, it stops processing events
/// from the event loop queue. It may still add new events to the queue in
/// response to, e.g., timers or receive-port messages. When the isolate is
/// resumed, it handles the already enqueued events.
/// @description Check that pause() does not stop the isolate to execute code.
/// @author
import "dart:isolate";
import "dart:math";
import "../../../Utils/expect.dart";
// indefinitely running isolate
entryPoint(List<SendPort> sendPorts) {
Random random = new Random();
int s = 0;
while (true) {
s = -s + random.nextInt(100);
test() async {
ReceivePort receivePort1 = new ReceivePort();
ReceivePort receivePort2 = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Isolate isolate =
await Isolate.spawn(entryPoint,
[receivePort1.sendPort, receivePort2.sendPort],
onExit: onExit.sendPort,
errorsAreFatal: true);
// make sure that isolate started its work
await receivePort1.first;
// check that messages are received from paused isolate
int count = 0;
await for (var _ in receivePort2) {
if (count++ == 1000000) {
// clean up
isolate.kill(priority: Isolate.immediate);
await onExit.first;
main() {