cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

WebWorker support #130

Closed alanpearce closed 2 weeks ago

alanpearce commented 11 years ago

I created a plugin to load a module as a worker, and created a shim to enable curl to load scripts from inside a worker. The makefiles were updated to build a worker-specific version and add to the kitchen sink.

There isn't any detection for worker support right now and I'm not quite certain about the best way to implement that, or if that should be a concern of this code (and curl).

There are a few ways I thought of to do this:

See #122 for more history.

alanpearce commented 11 years ago

I've been using this for a while and can't see anything else that needs adding at the moment.

I definitely think that using has! will be the best solution for conditional worker usage, but from reading a discussion seems as if it's not quite ready for use with curl yet. Until then, it's not that hard to live without.

alanpearce commented 11 years ago

Hmm, I decided to try the CJSM loader with this. Definitely doesn't work, but I think I'll wait for it to stabilise before looking at it. I also tried the node.js style of assigning module.exports as a function, which doesn't work when inside a worker.

At least rvalue require works.

unscriptable commented 11 years ago

Hey @alanpearce!

Lots of other stuff bogging me down, atm. Looking forward to seeing what you've created and want WebWorker support sometime soon! Thanks for being patient. :)

-- John

alanpearce commented 11 years ago

Thanks for your suggestion @scothis. It's definitely a better idea than just using importScripts, however I thought about it when I started and went with the simplest solution just to get it working. Initially it didn't seem like a big deal given that importScripts only blocks the worker thread.

@unscriptable I see there is some XHR code in the text! plugin. I'd like to use this in worker shim without duplicate code, but I'm not quite sure how you would want this organised. Let me know what you think and I'll get on it when I have time. :)