-
Notifications
You must be signed in to change notification settings - Fork 27
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
Feasability of asynchronous bindings? #46
Comments
@RickCarlino Thanks a lot for taking the time to write this up. Async bindings crossed my mind as well. I haven't thought things through yet, but here are my initial thoughts:
One thing that's missing to create useful examples is an API to easily push strings back into WAForth (maybe put them in the PAD area?) |
Thanks for the detailed response, @remko that makes sense. In my case, I ended up bringing in DEFER / IS from the 20xx standard.
As far as string support goes, I think putting them in the PAD area would make sense. Please let me know if you need any help! |
@RickCarlino Good tip! I added a This is the core of the code: forth.bindAsync("ip?", async () => {
const result = await (await fetch("https://api.ipify.org?format=json")).json();
forth.pushString(result.ip);
}); And then in Forth: : IP?-CB ( true c-addr n | false -- )
IF
." Your IP address is " TYPE CR
ELSE
." Unable to fetch IP address" CR
THEN
;
: IP? ( -- )
['] IP?-CB
S" ip?" SCALL
; |
@remko Thanks so much- will give it a look this evening. |
Currently, to add a binding to WAForth we use
Forth#bind
:This is good for 90% of cases out there, but I was curious how a developer might handle asynchronous binding usecases. Eg:
CASE 1: Inbound Async I/O
For dealing with inbound events (such as reacting to DOM
click
events, HTML5 geolocation events, etc..), I think it would be really easy to write an event handler:CASE 2: Outbound Async I/O
For outbound I/O operations like AJAX, things might not be so simple:
Ideas
bind
to return a promise and block the Forth VM until the promise resolves.Would something like this be reasonably possible with the current system?
The text was updated successfully, but these errors were encountered: