1

I'm trying my luck with a Mozilla extension.

I want to use the below code to read line by line from a file and store the content in an array. And I've been trying to use workers to do this task in the background, away from the main thread. The problem I'm facing is that I can't seem to pass neither "Components" nor the input stream to the worker in the postMessage() function without receiving a DataCloneError error.

https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O#Line_by_line

Any ideas on how and what to pass to the worker to make it work ? Or if not, then how to do this task asynchronously, if not by using workers ?

4

1 回答 1

1

JSON除了 pure到 worker之外,你不能传递任何东西Components,并且两者Components.classes都不能序列化到JSON.

看一下 JavaScript 模块NetUtil.jsm,使用网络实用程序进行本地文件读取似乎没问题。最终,一切仍然是套接字。

此外,您可以将代码片段中的代码与旧的setInterval.

于 2013-06-17T13:06:40.010 回答