public interface Worker extends AbstractWorker
Workers are background tasks that can be easily created and can send messages back to their creators. Creating a worker is as simple as calling the Worker()
constructor, specifying a script to be run in the worker thread.
Of note is the fact that workers may in turn spawn new workers as long as those workers are hosted within the same origin as the parent page. In addition, workers may use XMLHttpRequest
for network I/O, with the exception that the responseXML
and channel
attributes on XMLHttpRequest
always return null
.
For a list of global functions available to workers, see Functions available to workers.
If you want to use workers in extensions, and would like to have access to js-ctypes, you should use the ChromeWorker
object instead.
See Using web workers for examples and details.
Modifier and Type | Method and Description |
---|---|
EventListener |
getOnmessage()
An event listener that is called whenever a
MessageEvent with type message bubbles through the worker. |
void |
postMessage(Object message)
Sends a message to the worker's inner scope.
|
void |
postMessage(Object message,
Indexable messagePorts)
Sends a message to the worker's inner scope.
|
void |
setOnmessage(EventListener arg) |
void |
terminate()
Immediately terminates the worker.
|
void |
webkitPostMessage(Object message) |
void |
webkitPostMessage(Object message,
Indexable messagePorts) |
addEventListener, addEventListener, dispatchEvent, getOnerror, removeEventListener, removeEventListener, setOnerror
EventListener getOnmessage()
MessageEvent
with type message
bubbles through the worker. The message is stored in the event's data
member.void setOnmessage(EventListener arg)
void postMessage(Object message)
Sends a message to the worker's inner scope. This accepts a single parameter, which is the data to send to the worker. The data may be any value or JavaScript object that does not contain functions or cyclical references (since the object is converted to JSON internally).
aMessage
onmessage
handler. This may be any value or JavaScript object that does not contain functions or cyclical references (since the object is converted to JSON internally).void postMessage(Object message, Indexable messagePorts)
Sends a message to the worker's inner scope. This accepts a single parameter, which is the data to send to the worker. The data may be any value or JavaScript object that does not contain functions or cyclical references (since the object is converted to JSON internally).
aMessage
onmessage
handler. This may be any value or JavaScript object that does not contain functions or cyclical references (since the object is converted to JSON internally).void terminate()
Immediately terminates the worker. This does not offer the worker an opportunity to finish its operations; it is simply stopped at once.
void terminate();
void webkitPostMessage(Object message)
Copyright © 2018. All rights reserved.