Skip to content

Commit fd2eead

Browse files
committed
Add worker_threads to import and start to implement
1 parent 0d8d273 commit fd2eead

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

lib/src/node.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,14 @@ Future<RenderResult> _renderAsync(RenderOptions options) async {
8181
var file = options.file == null ? null : p.absolute(options.file);
8282
CompileResult result;
8383

84-
print(StackTrace.current);
85-
8684
if (isMainThread == true) {
87-
print(p.current);
85+
print("Creating worker thread");
8886
final worker = Worker(p.current, WorkerOptions(workerData: {options}));
8987
worker.on('message', (CompileResult msg) => result = msg);
9088
worker.on('error', (JSError error) {
9189
jsThrow(_wrapException(error));
9290
});
93-
} else {
91+
} else if (isMainThread == false) {
9492
if (options.data != null) {
9593
result = await compileStringAsync(options.data,
9694
nodeImporter: _parseImporter(options, start),
@@ -115,7 +113,9 @@ Future<RenderResult> _renderAsync(RenderOptions options) async {
115113
} else {
116114
throw ArgumentError("Either options.data or options.file must be set.");
117115
}
118-
parentPort.postMessage(result);
116+
parentPort?.postMessage(result);
117+
} else {
118+
throw UnsupportedError("Failed to create worker thread.");
119119
}
120120

121121
return _newRenderResult(options, result, start);

lib/src/node/worker_threads.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
// Copyright 2017 Google Inc. Use of this source code is governed by an
1+
// Copyright 2018 Google Inc. Use of this source code is governed by an
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
4-
@JS("workerThreads")
5-
library worker_threads;
6-
//Import is failing here
7-
84
import 'package:js/js.dart';
95

10-
@JS()
11-
external WorkerThreads get workerThreads;
6+
@JS("worker_threads")
7+
external WorkerThreads get worker_threads;
128

13-
bool isMainThread = workerThreads.isMainThread;
14-
ParentPort parentPort = workerThreads.parentPort;
9+
bool isMainThread = worker_threads?.isMainThread;
10+
ParentPort parentPort = worker_threads?.parentPort;
1511

1612
@JS()
1713
abstract class WorkerThreads {

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"url": "https://github.com/nex3"
1515
},
1616
"engines": {
17-
"node": ">=12.14.1"
17+
"node": ">=11.7.0"
1818
},
1919
"dependencies": {
2020
"chokidar": ">=2.0.0 <4.0.0"

tool/grind.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ void main(List<String> args) {
2626
pkg.chocolateyNuspec = _nuspec;
2727
pkg.homebrewRepo = "sass/homebrew-sass";
2828
pkg.homebrewFormula = "sass.rb";
29-
pkg.jsRequires = {"fs": "fs", "chokidar": "chokidar", "readline": "readline"};
29+
pkg.jsRequires = {
30+
"fs": "fs",
31+
"chokidar": "chokidar",
32+
"readline": "readline",
33+
"workerThreads": "worker_threads"
34+
};
3035
pkg.jsModuleMainLibrary = "lib/src/node.dart";
3136
pkg.npmPackageJson =
3237
json.decode(File("package/package.json").readAsStringSync())

0 commit comments

Comments
 (0)