-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Check Whether in Window or Webworker #14
Comments
Hey, @danidre14 Could you please let us know why you trying to use the client lib inside a web worker? The client lib is typically used as a normal browser script due to the following reasons:
Perhaps, you have a special case - so, we can discuss ;) |
Hi @shalithasuranga yes I have a special case. TLDR: For autosave backup files that aren't affected by the single-threaded JS. I am working on a game engine editor software for my own game engine; it is similar to Adobe Flash Professional or Wick Editor. It involves adding flevaclips (prefabs/textfields), graphics, audio, as well as applying scripts for the flevaclips. The main necessity is the "Test" function. It opens a new window with the "compiled/transpiled" JS code of the game. However, with this, since the test file was opened on the same thread as the editor, any blocking code (an infinite while loop the user uses, which is only detected at test/run-time) will freeze and crash even the editor, so users may lose data. Thus, I have implemented an autosave function that uses webworkers to autosave progress every 30 seconds. Therefore, even if the user runs an infinite while loop and crashes the editor, when the kill the application and reopen it, they have the option of retrieving the last autosaved file (since the web worker works on a different thread) For saving, I have created my own storage API that either uses the localstorage or indexeddb driver behind the scenes. That is why I proposed allowing the client lib inside a web worker...or at least, the storage part of it. |
This is a feature request.
Currently, when importing Neu as a script into webworkers, it uses the
window.NL_PORT
to make requests. window is underfined in webworkers, so all requests will silently fail. You'd have to fix that with by typingvar window = self;
in the worker right before importing the neu js file.Suggestion:
A fix would be to determine if in a webworker first, and populate the worker
NL_PORT
, else the window port. Tat way, requests such asNeu.storage
will work even in the worker.The text was updated successfully, but these errors were encountered: