Skip to content

Commit 627e522

Browse files
committed
Apply review feedbacks
1 parent 4729aca commit 627e522

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

lib/src/embedded/compilation_dispatcher.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// https://opensource.org/licenses/MIT.
44

55
import 'dart:convert';
6-
import 'dart:io' if (dart.library.js) 'js/io.dart';
7-
import 'dart:isolate' if (dart.library.js) 'js/isolate.dart';
86
import 'dart:typed_data';
97

108
import 'package:path/path.dart' as p;
@@ -13,7 +11,7 @@ import 'package:pub_semver/pub_semver.dart';
1311
import 'package:sass/sass.dart' as sass;
1412
import 'package:sass/src/importer/node_package.dart' as npi;
1513

16-
import '../io.dart' show FileSystemException;
14+
import '../io.dart';
1715
import '../logger.dart';
1816
import '../value/function.dart';
1917
import '../value/mixin.dart';
@@ -306,7 +304,7 @@ final class CompilationDispatcher {
306304
///
307305
/// This is used during compilation by other classes like host callable.
308306
Never sendError(ProtocolError error) {
309-
Isolate.exit(_sendPort, _serializePacket(OutboundMessage()..error = error));
307+
exitWorker(_sendPort, _serializePacket(OutboundMessage()..error = error));
310308
}
311309

312310
InboundMessage_CanonicalizeResponse sendCanonicalizeRequest(
@@ -436,7 +434,7 @@ final class CompilationDispatcher {
436434
} on StateError catch (_) {
437435
// The [SyncReceivePort] has been closed, exit the current isolate immediately
438436
// to avoid bubble the error up as [SassException] during [_sendRequest].
439-
Isolate.exit();
437+
exitWorker();
440438
}
441439
}
442440
}

lib/src/embedded/js/isolate.dart

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/src/embedded/js/sync_receive_port.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:js_interop';
66
import 'dart:typed_data';
77

88
import '../sync_receive_port.dart';
9-
import 'isolate.dart';
9+
import '../../io.dart';
1010
import 'js.dart';
1111
import 'sync_message_port.dart';
1212
import 'worker_threads.dart';

lib/src/io/interface.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5+
import 'dart:isolate' show SendPort;
6+
export 'dart:isolate' show SendPort;
7+
58
import 'package:watcher/watcher.dart';
69

710
/// An error thrown by [readFile].
@@ -89,6 +92,9 @@ String? getEnvironmentVariable(String name) => throw '';
8992
int get exitCode => throw '';
9093
set exitCode(int value) => throw '';
9194

95+
/// Exit the current dart isolate or nodejs thread
96+
Never exitWorker([SendPort? finalMessagePort, Object? message]) => throw '';
97+
9298
/// Recursively watches the directory at [path] for modifications.
9399
///
94100
/// Returns a future that completes with a single-subscription stream once the

lib/src/io/js.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:isolate' show SendPort;
78

89
import 'package:cli_pkg/js.dart';
910
import 'package:js/js.dart';
@@ -285,6 +286,13 @@ int get exitCode => _process?.exitCode ?? 0;
285286

286287
set exitCode(int code) => _process?.exitCode = code;
287288

289+
Never exitWorker([SendPort? finalMessagePort, Object? message]) {
290+
if (message != null) {
291+
finalMessagePort?.send(message);
292+
}
293+
_process?.exit(exitCode) as Never;
294+
}
295+
288296
Future<Stream<WatchEvent>> watchDir(String path, {bool poll = false}) async {
289297
if (!isNodeJs) {
290298
throw UnsupportedError("watchDir() is only supported on Node.js");

lib/src/io/vm.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io' as io;
8+
import 'dart:isolate';
89

910
import 'package:async/async.dart';
1011
import 'package:path/path.dart' as p;
@@ -103,6 +104,10 @@ DateTime modificationTime(String path) {
103104

104105
String? getEnvironmentVariable(String name) => io.Platform.environment[name];
105106

107+
Never exitWorker([SendPort? finalMessagePort, Object? message]) {
108+
Isolate.exit(finalMessagePort, message);
109+
}
110+
106111
Future<Stream<WatchEvent>> watchDir(String path, {bool poll = false}) async {
107112
var watcher = poll ? PollingDirectoryWatcher(path) : DirectoryWatcher(path);
108113

0 commit comments

Comments
 (0)