You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/base/worker.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Worker
2
2
Copyright 2018 Moddable Tech, Inc.
3
3
4
-
Revised: January 14, 2017
4
+
Revised: March 19, 2018
5
5
6
6
**Warning**: These notes are preliminary. Omissions and errors are likely. If you encounter problems, please ask for assistance.
7
7
@@ -20,13 +20,6 @@ Those familiar with Web Workers are strongly advised to read this document to un
20
20
21
21
This document contains a standalone description of the `Worker` class implemented in the Moddable SDK, without reference to the Web Worker specification. The [`worker` example](../../examples/base/worker/) is a simple example of using the `Worker` class.
22
22
23
-
## Scheduling
24
-
Depending on the host runtime, workers may be preemptively scheduled (e.g. run in parallel to each other and the main virtual machine, or they may be cooperatively scheduled (e.g. other virtual machines may only run after the current virtual machine yields). Cooperative scheduling is useful for isolating scripts but does not prevent one virtual machine from blocking another.
25
-
26
-
The Web Worker specification requires assumes that all Workers are preemptively scheduled. On some microcontrollers, preemptive scheduling is impractical (too much memory required) or nearly impossible (not supported by the host RTOS).
27
-
28
-
Each host of the Moddable SDK runtime decided whether to support multiple virtual machines. If it does, it then decides whether to support preemptive or cooperative scheduling. The ESP8266 runtime is built on a cooperative task model and so implements cooperative scheduling of virtual machines. The ESP32 is built on FreeRTOS, a preemptively scheduled RTOS, an so supports preemptive scheduling. When deciding whether to use multiple virtual machines in a project, check to see what is supported by the host runtime.
29
-
30
23
## class Worker
31
24
Scripts import the `Worker` class to be able to create a new worker.
32
25
@@ -132,6 +125,27 @@ The worker `onmessage` property contains a function which receives messages from
132
125
trace(msg, "\n");
133
126
}
134
127
128
+
## Shared Workers
129
+
The `SharedWorker` class is an API for working with shared virtual machines. The implementation is based on the [Shared Workers](https://html.spec.whatwg.org/multipage/workers.html#shared-workers-introduction) API from the web with some differences, including:
130
+
131
+
- The `close` function on the message port is not yet implemented, so Shared Workers cannot be terminated
132
+
- Workers are always launched from a module, never from a script file.
133
+
134
+
135
+
## class SharedWorker
136
+
Scripts import the `SharedWorker` class to be able to connect to a shared worker, creating the shared worker if it is not currently instantiated.
137
+
138
+
import {SharedWorker} from "worker";
139
+
140
+
**Note**: Examples and documentation needed.
141
+
142
+
## Scheduling
143
+
Depending on the host runtime, workers may be preemptively scheduled (e.g. run in parallel to each other and the main virtual machine, or they may be cooperatively scheduled (e.g. other virtual machines may only run after the current virtual machine yields). Cooperative scheduling is useful for isolating scripts but does not prevent one virtual machine from blocking another.
144
+
145
+
The Web Worker specification requires assumes that all Workers are preemptively scheduled. On some microcontrollers, preemptive scheduling is impractical (too much memory required) or nearly impossible (not supported by the host RTOS).
146
+
147
+
Each host of the Moddable SDK runtime decided whether to support multiple virtual machines. If it does, it then decides whether to support preemptive or cooperative scheduling. The ESP8266 runtime is built on a cooperative task model and so implements cooperative scheduling of virtual machines. The ESP32 is built on FreeRTOS, a preemptively scheduled RTOS, an so supports preemptive scheduling. When deciding whether to use multiple virtual machines in a project, check to see what is supported by the host runtime.
148
+
135
149
## xsbug support
136
150
The debugger for the XS virtual machine, `xsbug`, supports working with multiple virtual machines simultaneously. Each virtual machine appears in a separate tab with the name of the module path used to initialize the worker.
0 commit comments