-
Notifications
You must be signed in to change notification settings - Fork 354
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
Add native callbacks. #102
base: master
Are you sure you want to change the base?
Conversation
This is great, just what I was looking for! What does the following do?
|
Well, this does nothing, technically... it does not change anything (actually there is nothing I saw that was caused by this) |
@thejohncrafter altough this seems to run fine, I sometimes get into a situation where the callbacks are not executed anymore and the stack just keeps getting bigger and bigger... I need to push many callbacks quickly onto the stack to cause such behaviour. Any ideias on what could cause this? |
@ferrao sorry, I did not find a way to reproduce this bug yet. Can you provide me the code causing it, please ? |
@thejohncrafter after some banging against the wall I managed to find my problem and it has nothing to do with your code, it's actually already reported here #84 , once i fixed that everything worked as expected! |
@NeilFraser If this isn't a feature that you're interested in merging into JS-Interpreter, do you think this is something that users of JS-Interpreter could implement on their end? It feels like the solution to this on the user side would be very similar to the way a user can implement multi threaded js? Just curious if you had any thoughts on the best way for a user to implement this using JS-Interpreter in its current state. |
Unfortunately, this doesn't work with the latest interpreter.js, but it would really be nice to have a way of calling anonymous interpreted functions passed native functions more directly than is currently possible. |
I've added PR #201 to do something similar to this, but for newer versions of the interpreter. |
I implemented a utility function (
queueCall
) to call back a pseudo function from the native side. This allows to create "true asynchronous" calls, from the interpreter's point of view. I also wrote a demo ("Callback Demo"), and added some documentation.Basic usage :
This works by shifting the given function at the bottom of the stack (just on top of the
Program
node), so the function is called just before the program ends (that's why I say it's "queued"). This makes sure that there is no thread-related unsolvable bugs...I would have liked to re-generate the compressed bundle myself, but I do not know how to (maybe it could be interesting to put a notice in
README.md
explaining how to do it).(I apologize if my English is not good, I'm not a native speaker... ¯_(ツ)_/¯ )