Created
July 22, 2019 18:02
-
-
Save aam/916047c1db7bd0d466f926c98d1af902 to your computer and use it in GitHub Desktop.
Spawn 10 dart2js: `out/ReleaseX64/dart dart2jsx10.dart --libraries-spec=sdk/lib/libraries.json hello.dart`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:isolate'; | |
import 'pkg/compiler/lib/src/dart2js.dart' as dart2jsMain; | |
void run(List<dynamic> params) async { | |
final SendPort sendPort = params[0]; | |
final List arguments = params[1]; | |
await dart2jsMain.internalMain(arguments); | |
sendPort.send(true); | |
} | |
void main(List<String> arguments) async { | |
List<RawReceivePort> receivePorts = <RawReceivePort>[]; | |
List<Completer> completers = <Completer>[]; | |
for (int i = 0; i < 10; i++) { | |
Completer completer = Completer(); | |
RawReceivePort receivePort = RawReceivePort((_) { | |
completer.complete(); | |
}); | |
receivePorts.add(receivePort); | |
completers.add(completer); | |
Isolate.spawn(run, <dynamic>[receivePort.sendPort, arguments]); | |
} | |
await Future.wait(completers.map<Future>((completer) => completer.future)); | |
for (RawReceivePort receivePort in receivePorts) { | |
receivePort.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment