hybrid icon indicating copy to clipboard operation
hybrid copied to clipboard

importScripts()

Open alastaircoote opened this issue 8 years ago • 1 comments

Doesn't currently exist as we've been using code bundlers that mean it isn't necessary, but it's a key part of the spec a lot of people use.

Key issue with it is that it's synchronous, and can involve network operations, which can take a lot of time. If they happen on the main thread then the app is going to become unresponsive. I'm also not entirely sure what happens when we try to execute JS in the context of a function call that's already happening.

There are two implementation options:

  • Take worker operations off the main thread (actually not difficult, PromiseKit has thenInBackground, then evaluate everything synchronously. But still need to resolve potential issue of evaluating code while we're evaluating code.
  • Apply a regex to the downloaded code and pick up importScripts() calls, replace them with script content. Sounds gross, but I can't think of any reason why it wouldn't work in the exact same way.

alastaircoote avatar Dec 19 '16 17:12 alastaircoote

Currently using a regex to grab importScripts() calls and replace them with script content when the worker is first loaded. Not great, but it'll have to do for now.

alastaircoote avatar Jan 12 '17 15:01 alastaircoote