Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML5 web worker support? #76

Closed
cosecantt opened this issue Mar 15, 2015 · 8 comments
Closed

HTML5 web worker support? #76

cosecantt opened this issue Mar 15, 2015 · 8 comments

Comments

@cosecantt
Copy link

Hi there. I would like to know if this wrapper works inside the web worker? If not, adding this feature would greatly be helpful. Thank you.

@dfahlander
Copy link
Collaborator

Hi! I have not tested it from a web worker but I understand that it would be important use case. Having that said, I believe there are good chances that Dexie would work in a web worker if including it as requirejs module. It is written to adapt to both window- and non-window environments by using "this" instead of window for global scope and all external dependencies are picked from a local "window" variable that actually is initiated from "this" at global scope, which in a web worker would be DedicatedWorkerGlobalScope.

Therefore I hereby ask the community to test that out and report back on this issue whether Dexie is supported from a web worker environment or not. If not, I will be helpful correcting what is needed to be corrected to make it work.

@cosecantt
Copy link
Author

Hi David,
I tried to import the scripts in web workers and got the following error:
Dexie.js:3098 Uncaught ReferenceError: window is not defined

@dfahlander
Copy link
Collaborator

Thanks for testing! Suppose you were using dist/latest/Dexie.js. If so, it seems that we'd have to change the way it detects non-window environments.

@dfahlander
Copy link
Collaborator

I am creating a unit test for it now and I got the same error. Solution hopefully on its way...

dfahlander added a commit that referenced this issue Mar 16, 2015
Unit tested and solved issue#76. Dexie can now be used from within a Web
Worker.

Unit test runs successfully in IE11, Chrome and Opera but fails in
Firefox 36. Should be supported in Firefox 37 according to the following
Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=701634 .
@dfahlander
Copy link
Collaborator

Solution checked in. Please try it using src/Dexie.js because it is not yet released to dist.

@cosecantt
Copy link
Author

Hi David,
I did a quick test. It worked by using require.js. I mean I was able to access previously entered indexed db data. Without require.js it did not work while it was working within the main thread. Any solutions for that? Anyway I will do more checks and inform if any issues found. It would be great if you add some examples or tutorials on the dexie.js usage within Web Worker. Thank you!

@dfahlander
Copy link
Collaborator

Are you sure? My unit test did not use requrejs. I just did importScripts("src/Dexie.js") in the worker and then I could start using it

@cosecantt
Copy link
Author

Sorry. I think it was my mistake. I was using dexie in setInterval function and the first was empty I did not wait until the second interval. It was fine from the second interval. Many thanks.

dfahlander added a commit that referenced this issue Mar 18, 2015
Addons Dexie.Syncable and Dexie.Observable made compliant with
WebWorkers also. Made it possible to test that in the unit test suite
when including the addons.
dfahlander added a commit that referenced this issue Apr 20, 2015
Ever since commit 722aa20 that resolved
#76 (Web Worker support), the code completion when using Dexie in Visual
Studio has been broken.

The reason was that 'window' was replaced with 'self' to support
WebWorker environment. But self is not handled by VS intellisense
engine. To work around this, 'self' is replaced with 'self || window'
and the nice intellicense came back to live...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants