blob: ddfd291f6ce2e619b98a7ed3b3d0ed0945b5e8dc [file] [log] [blame]
// Copyright (c) 2016, 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.
/// A library for utility functions for dealing with isolates.
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
/// Like [Isolate.spanwUri], except that this only returns once the Isolate has
/// exited.
/// If the isolate produces an unhandled exception, it's printed to stderr and
/// the [exitCode] variable is set to 255.
/// If [buffered] is `true`, this uses [spawnBufferedUri] to spawn the isolate.
Future runUri(Uri url, List<String> args, Object message,
{bool buffered: false,
bool checked,
bool automaticPackageResolution: false,
Uri packageConfig}) async {
var errorPort = new ReceivePort();
var exitPort = new ReceivePort();
await Isolate.spawnUri(url, args, message,
checked: checked,
automaticPackageResolution: automaticPackageResolution,
packageConfig: packageConfig,
onError: errorPort.sendPort,
onExit: exitPort.sendPort);
errorPort.listen((list) {
stderr.writeln("Unhandled exception:");
exitCode = 255;
await exitPort.first;