-
Notifications
You must be signed in to change notification settings - Fork 47
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
Documentation: Use of Modules vs Context #135
Comments
There is only three (and half) reasons for using Modules:
Yes, you can load set of libraries into Modules. It's main function of No, you cannot reuse modules with different Contexts. Because of some internal optimizations, AST builded with one Context is not recommended to use with another. It is possible with directly using types from namespaces No performance penalty or other difference. For the long time since start of development of this library |
OK, that's good, so what is the relationship between |
In this scenario you need to create |
I did see that diagram, but it appears that only one https://github.com/nilproject/NiL.JS/blob/develop/NiL.JS/Core/Context.cs#L84 Anything referring to Line 1309 in 960a5f2
I see the |
This line in Because of this lines Lines 41 to 42 in 66f2a9a
CurrentContext is thread dependent. See implementation of Activate().I checked this in multithreaded scenario and already fixed caught bugs. |
Ah, awesome. It was the JSValue reference that was concerning me. |
It means that after calling this method each context, created via if you do not create a context for each thread, then behavior of contexts will be the same as if there was only one thread. Context do not handle switch between threads. |
OK, two problems with this approach. Firstly, it appears that the use of the GlobalContext introduces threading issues. If we use a GlobalContext as documented to handle incoming web requests, we get periodic Secondly, the Context should not be handling any thread functionality itself. Javascript is a single-threaded language, so the only way multiple instances should exist is if a user creates them. If someone creates a WinForms app the UI will be on a different thread to the app, so it's standard practise to have to invoke calls on the other thread. I still don't see the purpose of the Activate and Deactivate methods, as they talk to a global static collection of Context instances, which seems completely wrong. |
As I understand, you got a "Global static collection of Context instances" is a |
No, the exception is "Operation is not valid due to the current state of the object", and is not thrown in the main library but appears to be thrown by the Kestrel webserver. I'll try and reproduce it tomorrow. I'll look at the ThreadStatic instance you mention, as I've never used it. For now we're having to create instances of Contexts per project (not thread) and wrap all evaluations in a lock to avoid clashes. |
Can you give an overview of the reason for use of Modules vs simply Eval'ing scripts to a Context?
Can we load a set of libraries into Modules?
Can Modules be re-used in different Contexts?
Are there any performance gains or modularity advantages?
The text was updated successfully, but these errors were encountered: