Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run embedded compilations across multiple isolates #1981

Merged
merged 12 commits into from
Jun 6, 2023
12 changes: 10 additions & 2 deletions lib/src/embedded/isolate_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class IsolateDispatcher {
/// even across isolates. See sass/dart-sass#1959.
final _isolatePool = Pool(15);

/// Whether the underlying channel has closed and the dispatcher is shutting
/// down.
var _closed = false;

IsolateDispatcher(this._channel);

void listen() {
Expand Down Expand Up @@ -98,6 +102,7 @@ class IsolateDispatcher {
}, onError: (Object error, StackTrace stackTrace) {
_handleError(error, stackTrace);
}, onDone: () {
_closed = true;
for (var isolate in _allIsolates) {
nex3 marked this conversation as resolved.
Show resolved Hide resolved
isolate.kill();
}
Expand Down Expand Up @@ -156,9 +161,12 @@ class IsolateDispatcher {
_handleError(error, stackTrace),
onDone: () {
_activeIsolates.remove(compilationId);
_inactiveIsolates.add(isolate);
if (_closed) {
isolate.sink.close();
} else {
_inactiveIsolates.add(isolate);
}
resource.release();
channel.sink.close();
});
_activeIsolates[compilationId] = channel.sink;
return channel.sink;
Expand Down