Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Workers message order

Is it save to rely on the order of messages passed from the main thread to a single Web Worker being retained? For instance, if I do

worker.postMessage(1);
worker.postMessage(2);

will the worker certainly get to process the first message before the second one?

like image 340
Jan Pöschko Avatar asked Nov 24 '25 15:11

Jan Pöschko


1 Answers

As long as you are working with the same worker to post the messages, I think it will. You can easily test this if you want. Make a loop and post messages with a certain order. If you always receive the messages in the same order as you post them, you can relay on it, that this will be the case.

like image 137
Kristof Degrave Avatar answered Nov 26 '25 06:11

Kristof Degrave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!