0

我有一个网络工作者,它发出大约 30 个 AJAX 请求,在每个请求之后,它使用 postMessage 向 UI 发送一条消息以记录进度。例如:

postMessage({type: "progress", name: "customers", message: "Success" }).

大约 10-20 次请求后(并不总是相同的数量),出现以下错误:

未捕获的 SyntaxError: 没有足够的参数

如果我删除 postMessage 调用,一切正常,如果我添加额外的 postMessage 调用,网络工作者会在更少的请求后给出错误。

它似乎还取决于数据的类型,如果 postMessage 调用包含 JSON 对象而不是字符串,则 web worker 会更快死亡。

有谁知道为什么会这样?

4

1 回答 1

0

It turns out that, at least in my case, postMessage fails if it is called multiple times in a short amount of time (milliseconds)

Calling postMessage only every 500 milliseconds solved the issue for me.

于 2011-05-06T06:56:31.010 回答