@@ -29,13 +29,11 @@ communicate with their protocol buffer equivalents.
29
29
30
30
## Worker Communication and Management
31
31
32
- The way Dart VM launches lightweight isolates versus Node.js launches worker
33
- threads are very different.
34
-
35
- In Dart VM, the lightweight isolates share program structures like loaded
36
- libraries, classes, functions, etc., even including JIT optimized code. This
37
- allows main isolate to spawn child isolate with a reference to the entry point
38
- function.
32
+ The way the Dart VM launches lightweight isolates is very different from how
33
+ Node.js launches worker threads. In the Dart VM, the lightweight isolates share
34
+ program structures like loaded libraries, classes, functions, and so on, even
35
+ including JIT optimized code. This allows main isolate to spawn child isolate
36
+ with a reference to the entry point function.
39
37
40
38
```
41
39
┌─────────────────┐ ┌─────────────────┐
@@ -55,21 +53,21 @@ function.
55
53
56
54
In Node.JS, the worker threads do not share program structures. In order to
57
55
launch a worker thread, it needs an entry point file, with the entry point
58
- function effectly hard-coded in the entry point file. While it's possible
59
- to have a separate entry point file for the worker threads, it requires more
60
- complex packaging changes with ` cli_pkg ` , therefore the main thread and the
61
- worker threads share [ the same entry point file] ( js/executable.dart ) , which
62
- decides what to run based on ` worker_threads.isMainThread ` .
56
+ function effectly hard-coded in that file. While it's possible to have a
57
+ separate entry point file for the worker threads, it would require complex
58
+ packaging changes within ` cli_pkg ` , so instead the main thread and the worker
59
+ threads share [ the same entry point file] ( js/executable.dart ) , which decides
60
+ what to run based on ` worker_threads.isMainThread ` .
63
61
64
62
```
65
63
if (worker_threads.isMainThread) { if (worker_threads.isMainThread) {
66
64
mainEntryPoint(); mainEntryPoint();
67
65
} else { } else {
68
- workerEntryPoint(); new Worker(process.argv[1], { workerEntryPoint();
69
- } argv: process.argv.slice(2), }
70
- workerData: channel.port2,
71
- ┌────────────────────────────────────┐ transferList: [channel.port2] ┌────────────────────────────────────┐
72
- │ Main Thread │ }) │ Worker Thread │
66
+ workerEntryPoint(); new Worker(process.argv[1], { workerEntryPoint();
67
+ } argv: process.argv.slice(2), }
68
+ workerData: channel.port2,
69
+ ┌────────────────────────────────────┐ transferList: [channel.port2] ┌────────────────────────────────────┐
70
+ │ Main Thread │ }) │ Worker Thread │
73
71
│ ├────────────────────────────────────────────────────────────►│ │
74
72
│ │ │ │
75
73
│ ┌────────────────────────────────┐ │ Synchronous Messaging │ ┌────────────────────────────────┐ │
0 commit comments