jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

Is it possible to implement worker in JerryScript?

Open Sherry0901 opened this issue 4 years ago • 4 comments

Is it possible to implement worker(like web worker) in JerryScript? if it's available, where can I get some examples or guides?

Sherry0901 avatar Dec 08 '21 07:12 Sherry0901

Hi, please check the following example: https://github.com/jerryscript-project/jerryscript/blob/master/docs/02.API-REFERENCE.md#jerry_context_alloc

rerobika avatar Dec 08 '21 09:12 rerobika

thanks! I see, so JerryScript can create multi-threads. But I am still confused about the details. How can I implement postMessage,addEventListener,removeEventListener...in JerryScript? @rerobika

Sherry0901 avatar Dec 09 '21 07:12 Sherry0901

I see, so JerryScript can create multi-threads.

Nope, JerryScript cannot create threads. The linked example only shows that the engine is able to work in a multi threaded context. Please note that those independent contexts cannot pass value to each other.

If I were you I'd definitely use Promises or async functions to build and own event queue to handle the listener events. However, it's still single threaded, but the jobs can communicate with each other.

rerobika avatar Dec 09 '21 14:12 rerobika

Thanks for your advice! I'll try it.

Sherry0901 avatar Dec 10 '21 02:12 Sherry0901