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: content/guide/multithreading.md
+50-50
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ For optimal results when using the Workers API, follow these guidelines:
22
22
Creating a new worker is simple, all you need is to call the `Worker()` constructor with a path to the worker script (relative to current file, or an aliased path eg. `~/path/to/worker.ts`). The worker itself can be written in JavaScript or TypeScript.
23
23
24
24
```ts
25
-
const myWorker =newWorker('./worker.ts');
25
+
const myWorker =newWorker('./worker.ts')
26
26
```
27
27
28
28
### Sending messages to a worker
@@ -31,7 +31,7 @@ To send messages to the worker, use the [`postMessage()`](#postmessage) method o
31
31
32
32
```ts
33
33
// send myMessage to the worker
34
-
myWorker.postMessage(myMessage);
34
+
myWorker.postMessage(myMessage)
35
35
```
36
36
37
37
### Receiving messages from a worker
@@ -41,9 +41,9 @@ To receive messages from the worker, use the [`onmessage`](#onmessage) callback
41
41
```ts
42
42
// attach a message handler that will receive messages from the worker thread
43
43
myWorker.onmessage= (e) => {
44
-
console.log('Message received from the worker thread.');
45
-
const data =e.data;// data from the worker
46
-
};
44
+
console.log('Message received from the worker thread.')
45
+
const data =e.data// data from the worker
46
+
}
47
47
```
48
48
49
49
### Sending messages to main thread
@@ -52,7 +52,7 @@ To send messages back to the main thread use the [`self.postMessage()`](#postmes
52
52
53
53
```ts
54
54
// send the workerResult back to the main thread
55
-
self.postMessage(workerResult);
55
+
self.postMessage(workerResult)
56
56
```
57
57
58
58
### Receiving messages from main thread
@@ -62,9 +62,9 @@ To receive messages in the worker, use the [`self.onmessage`](#onmessage-1) even
62
62
```ts
63
63
// attach a message handler that will receive the messages from the main thread
64
64
self.onmessage= (e) => {
65
-
console.log('Message received from the main thread.');
66
-
const data =e.data;// data from myMessage
67
-
};
65
+
console.log('Message received from the main thread.')
66
+
const data =e.data// data from myMessage
67
+
}
68
68
```
69
69
70
70
<!-- ### Sending messages to and from a worker
@@ -102,7 +102,7 @@ self.onmessage = (e) => {
102
102
If you need to stop executing the worker, you can terminate it from the main thread using the `terminate` method on the `Worker` instance:
103
103
104
104
```ts
105
-
myWorker.terminate();
105
+
myWorker.terminate()
106
106
```
107
107
108
108
The worker thread is killed immediately.
@@ -115,20 +115,20 @@ Runtime errors inside the worker are reported back to the main thread through th
115
115
myWorker.onerror= (e) => {
116
116
console.log(
117
117
`Error occured in the worker thread in file ${e.filename} on line ${e.lineno}`
118
-
);
119
-
console.log(e.message, e.stackTrace);
120
-
};
118
+
)
119
+
console.log(e.message, e.stackTrace)
120
+
}
121
121
```
122
122
123
123
The worker can also self-handle errors by setting up an `onerror` handler, which can mark the error as "handled" and prevent the callback on the main thread from being called.
124
124
125
125
```ts
126
126
self.onerror= (e) => {
127
-
console.log('Error occured, error:', e);
127
+
console.log('Error occured, error:', e)
128
128
129
129
// return true-like to stop the event from being passed onto the main thread
130
-
returntrue;
131
-
};
130
+
returntrue
131
+
}
132
132
```
133
133
134
134
## Workers API
@@ -146,7 +146,7 @@ Creates an instance of a Worker and spawns a new OS thread, where the script poi
146
146
### postMessage
147
147
148
148
```ts
149
-
myWorker.postMessage(message);
149
+
myWorker.postMessage(message)
150
150
```
151
151
152
152
Sends a JSON-serializable message to the associated script's `onmessage` event handler.
@@ -156,7 +156,7 @@ Sends a JSON-serializable message to the associated script's `onmessage` event h
156
156
### terminate
157
157
158
158
```ts
159
-
myWorker.terminate();
159
+
myWorker.terminate()
160
160
```
161
161
162
162
Terminates the execution of the worker thread on the next run loop tick.
@@ -166,7 +166,7 @@ Terminates the execution of the worker thread on the next run loop tick.
Handles uncaught errors occurring during execution of functions inside the Worker Scope (worker thread).
@@ -257,7 +257,7 @@ After `onerror` is called in the worker thread, execution is not terminated and
257
257
```ts
258
258
self.onclose=function handler() {
259
259
// do cleanup work
260
-
};
260
+
}
261
261
```
262
262
263
263
Handles any "clean-up" work. Suitable for freeing up resources, closing streams and sockets.
@@ -270,7 +270,7 @@ Handles any "clean-up" work. Suitable for freeing up resources, closing streams
270
270
In order to use `setTimeout`, `setInterval`, or other globals coming from the `@nativescript/core`, you will need to include them in your worker script:
Copy file name to clipboardExpand all lines: content/parts/troubleshooting-increase-deployment-target.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -20,4 +20,4 @@ end
20
20
21
21
In this example we are setting it to `13.0` - change it to a version that makes sense for your project. Some libraries will require higher targets, so in most cases find the highest required target, and use that as your deployment target. Make sure to match both `build.xcconfig` and `Podfile` versions.
22
22
23
-
In case this doesn't resolve the issue, you can often [delete the XCode DerivedData](#deleting-xcode-deriveddata).
23
+
In case this doesn't resolve the issue, you can often [delete the XCode DerivedData](#deleting-xcode-deriveddata).
0 commit comments