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

[spike] Implement setTimeout #177

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[spike] Implement setTimeout #177

wants to merge 1 commit into from

Conversation

ianks
Copy link
Contributor

@ianks ianks commented Oct 2, 2020

This PR is a spike at adding an optional setTimeout implementation. The current code is very raw, but wanted to post is so I could get some early feedback. Thoughts?

@ianks ianks marked this pull request as draft October 2, 2020 05:39
@SamSaffron
Copy link
Collaborator

SamSaffron commented Oct 2, 2020

We have to be super careful around lifetimes here between the 2 vMs we don't want to segfault cause a context with timeouts got disposed.

I can see people wanting both this and setInterval though I wonder if this scheduling should happen directly in C to avoid depending on Ruby here

Do you have a particular use case here you are blocked on.

Maybe a good opening move here is simply offering some level of interoperability in general?

fn = ctx.eval("function(x) {return 40 + x;}")
puts ctx.call(fn, 2)
=> 42

Ideally the amount of info we leak between VMs though should be minimal. So stuff like this should not segfault or lead to any surprises.

fn = ctx.eval("function(x) {return 40 + x;}")
ctx.dispose
p fn
ctx.call(fn, 2)

@ianks
Copy link
Contributor Author

ianks commented Oct 2, 2020

I can see people wanting both this and setInterval though I wonder if this scheduling should happen directly in C to avoid depending on Ruby here

I was wondering this as well. It seems like there is support in libplatform for an event loop that does this type of thing, but the documentation is scarce. Overall, if it is possible, I do think it is a better approach.

Here are some examples of how others have implemented timers:

If anyone stumble on any information about implementing this in an embedded context, please post it here! The documentation on it is hard to come by.

Do you have a particular use case here you are blocked on.

We are SSR React in our codebase with GraphQL. Having the ability to make those queries async would speed things up a bunch.

Maybe a good opening move here is simply offering some level of interoperability in general?

fn = ctx.eval("function(x) {return 40 + x;}")
puts ctx.call(fn, 2)
=> 42

👍

@ianks
Copy link
Contributor Author

ianks commented Oct 22, 2020

this task is beyond my current abilities for v8 and c++, so i won’t be able to implement. if anyone wants to take this on, have at it!!

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.

2 participants