javascript - Web worker onerror - Stack Overflow

Do web workers provide some method of finding out what data was posted to them if they fail?So if I hav

Do web workers provide some method of finding out what data was posted to them if they fail?

So if I have the following code is there anyway to find out the contents of someData in the onerror handler if it fails or would I just have to keep track of it?

var someData = {...};
myWorker.postMessage(someData);

Do web workers provide some method of finding out what data was posted to them if they fail?

So if I have the following code is there anyway to find out the contents of someData in the onerror handler if it fails or would I just have to keep track of it?

var someData = {...};
myWorker.postMessage(someData);
Share Improve this question asked Jul 18, 2014 at 21:51 Berry BlueBerry Blue 16.6k22 gold badges77 silver badges147 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Web workers do not provide any dedicated method of finding out what data was posted to them if they fail.

But that's quite easy to do manually, you can either handle onerror from outside, or do the deeper inspection in the onmessage handler from inside of the worker (where you have access to the message event):

// this one-liner was wrapped in order to improve legibility
var w = new Worker( URL.createObjectURL(
    new Blob([ " self.onmessage = function (evt) {\
        console.log(evt.data);\
        throw new Error('SOMETHING.WENT.WRONG.'); } "
    ])
));
w.onerror = function (err) {
    console.log('worker is suffering!', err)
};
w.postMessage(123);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744985879a4604604.html

相关推荐

  • javascript - Web worker onerror - Stack Overflow

    Do web workers provide some method of finding out what data was posted to them if they fail?So if I hav

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信