I’m trying to move a fairly slow function off of the main thread, but the code I’m relocating depends on a module I’ve written using the Components object. My understanding is that Components is forbidden due to its lack of thread safety.
I’ve spent time sorting through documentation on MDN and my head is swimming; it seems like Firefox has a dozen different ways of opening files and they variously take URIs, native paths, or any number of incompatible objects generated from yet more complicated interfaces deep in the guts of the browser, and I can’t tell how they interoperate or what would begin to be appropriate for this. The more I read, the less I know what I’m doing. I’m guessing the real answer is simple and I’m sorry to ask to be spoonfed, but:
A) Is it okay to open a (local) file from inside a worker thread?
B) Could I have an example of this?
C) …preferably an example using a URI instead of a native path?
D) …preferably without instantiating and passing any objects from outside the worker?
I hail from the Perl tradition of while(<>) {} and Firefox has seemingly the most redundant/obtuse/terrifying system(s) of File I/O I have seen.
The easiest way to read whole files is to use XMLHttpRequest. However if you only need part of a file then you may be able to use the File API. See https://developer.mozilla.org/En/DOM/Worker/Functions_available_to_workers