{"json_modified": "2016-09-25T03:12:14.230533", "uuid": "3beddfd2-9dc3-4626-aec8-9df29d25ac41", "title": "PromiseWorker.jsm", "url": "/en-US/docs/Mozilla/JavaScript_code_modules/PromiseWorker.jsm", "tags": ["Extensions", "Workers", "NeedsContent", "Guide", "API", "js-ctypes", "Add-ons", "add-ons"], "translations": [], "modified": "2016-09-25T03:12:14", "label": "PromiseWorker.jsm", "localization_tags": [], "locale": "en-US", "id": 156291, "last_edit": "2016-09-25T03:12:06", "summary": "A PromiseWorker
is a ChromeWorker
except instead of calling postMessage()
to send a message, you call post()
, which returns a Promise
. JavaScript files imported into the worker scope and main thread scope which allows posting to the worker and receiving in the form of a promise. Like\u00a0ChromeWorker
objects, PromiseWorker
is mostly used for js-ctypes but it is not limited to that. There is no XPCOM access, similar to ChromeWorker
. This answers the question \"When should I use a PromiseWorker
?\", and the answer is, whenever you would normally use a ChromeWorker
, but want postMessage
to return promises.", "sections": [{"id": "Summary", "title": "Summary"}, {"id": "PromiseWorker.jsm", "title": "PromiseWorker.jsm"}, {"id": "PromiseWorker.js", "title": "PromiseWorker.js"}, {"id": "Setup_and_usage", "title": "Setup and usage"}, {"id": "Worker_file", "title": "Worker file"}, {"id": "Main_thread_file", "title": "Main thread file"}, {"id": "Sending_a_message_from_main_thread", "title": "Sending a message from main thread"}, {"id": "post", "title": null}, {"id": "Syntax", "title": "Syntax"}, {"id": "Parameters", "title": "Parameters"}, {"id": "Returns", "title": "Returns"}, {"id": "Transferring_special_data_from_main_thread_to_worker", "title": "Transferring special data from main thread to worker"}, {"id": "aTransferList", "title": "aTransferList"}, {"id": "BasePromiseWorker.Meta", "title": "BasePromiseWorker.Meta"}, {"id": "Sending_a_message_from_worker", "title": "Sending a message from worker"}, {"id": "Resolving_the_Promise", "title": "Resolving the Promise"}, {"id": "Transferring_special_data_from_worker_to_main_thread", "title": "Transferring special data from worker to main thread"}, {"id": "Rejecting_the_Promise", "title": "Rejecting the Promise"}, {"id": "Catching_the_Promise", "title": "Catching the Promise"}, {"id": "Complete_example", "title": "Complete example"}, {"id": "Worker_file_2", "title": "Worker file"}, {"id": "myWorker.js", "title": null}, {"id": "Main_thread_file_2", "title": "Main thread file"}, {"id": "bootstrap.js", "title": "bootstrap.js"}, {"id": "Result", "title": "Result"}, {"id": "Other_examples", "title": "Other examples"}, {"id": "See_also", "title": "See also"}], "slug": "Mozilla/JavaScript_code_modules/PromiseWorker.jsm", "review_tags": ["technical"]}