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

Add native callbacks. #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thejohncrafter
Copy link

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 :

interpreter.queueCall(pseudoFunction, [pseudoArguments]);
interpreter.run();

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... ¯_(ツ)_/¯ )

@ferrao
Copy link

ferrao commented May 24, 2017

This is great, just what I was looking for!

What does the following do?

arguments: [this.createPrimitive('Hello !')],

@thejohncrafter
Copy link
Author

Well, this does nothing, technically... it does not change anything (actually there is nothing I saw that was caused by this)
This is a line of code I wrote when testing, and that I forgot to remove because it was not affecting the behavior of the interpreter (I'll go deeper in the explanation as soon as I'll understand everything correctly).
Thank you for pointing it out !

@ferrao
Copy link

ferrao commented May 29, 2017

@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?

@thejohncrafter
Copy link
Author

@ferrao sorry, I did not find a way to reproduce this bug yet. Can you provide me the code causing it, please ?

@ferrao
Copy link

ferrao commented May 30, 2017

@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!

@NAllred91
Copy link

@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.

@Webifi
Copy link

Webifi commented Nov 8, 2020

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.

@Webifi
Copy link

Webifi commented Nov 12, 2020

I've added PR #201 to do something similar to this, but for newer versions of the interpreter.

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

Successfully merging this pull request may close these issues.

4 participants