Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

how does async work / how is async going to work in starlight #48

Closed
andrieshiemstra opened this issue Jun 18, 2021 · 5 comments
Closed

Comments

@andrieshiemstra
Copy link
Contributor

andrieshiemstra commented Jun 18, 2021

Based on what you said in #44 i had a look at function.rs and generator.rs and i don't quite understand how that is going to work async

JavaScript engines typically rely on running in an EventLoop and provide a way to expose jobs which should be added to that loop.

QuickJS has an internal vec of pending jobs accessed by calling JS_IsJobPending() and then JS_ExecutePendingJob() (the downside of this is that you have call those after everything you do with the quickjs runtime).

Spidermonkey has a more elegant solution, you can add a hook (fn/closure) for when an async job has to run (SetJobQueue())

For quickjs I implemented an generic EventLoop here: https://github.com/HiRoFa/utils/blob/master/src/eventloop.rs

For Promises in starlight i was planning to add a simple hook (vm.registerJobAddHookThingy(Fn(Job)) which in turn adds the job to the EventLoop so it wil run async (but in the same thread) but i'm wondering if that's the way you want to go or have an other solution for async jobs...?

@playXE
Copy link
Collaborator

playXE commented Jun 18, 2021

Based on what you said in #44 i had a look at function.rs and generator.rs and i don't quite understand how that is going to work async

I was talking on how async function state should be saved/restored and not the actual impl.

I don't actually know what is the best way to implement promises and async fns for JS engine actually. All my experience with coroutines is all in greenie which implements green threads and nothing more.

@andrieshiemstra
Copy link
Contributor Author

i'll see what I can come up with and get back to you with a suggestion later ok?

@playXE
Copy link
Collaborator

playXE commented Jun 18, 2021

That would be awesome! I still haven't finished exams so I do not have much time to work on such complex things like async. :(

@andrieshiemstra
Copy link
Contributor Author

That would be awesome! I still haven't finished exams so I do not have much time to work on such complex things like async. :(

Well get back to studying then! i don't want to be the one that distracted you from your exams! ;)

Good luck with your exams!

@playXE
Copy link
Collaborator

playXE commented Jun 19, 2021

Good luck with your exams!

Thank you!

Btw if you have questions about internals of Starlight I guess GH Discussions is better place. :)

@playXE playXE closed this as completed Jun 20, 2021
@Starlight-JS Starlight-JS locked and limited conversation to collaborators Jun 20, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants