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

experiment with stackful for easier async interop #38

Open
jprochazk opened this issue Jul 8, 2023 · 0 comments
Open

experiment with stackful for easier async interop #38

jprochazk opened this issue Jul 8, 2023 · 0 comments
Assignees

Comments

@jprochazk
Copy link
Owner

jprochazk commented Jul 8, 2023

stackful is a library which exposes primitives to construct stackful coroutines and make them interop easily with an external async runtime. We could either try to use it directly, or construct a similar abstraction of our own. The gist of it is that we want to be able to do this:

// `eval` returns a future which is awaited
vm.eval("sleep(1)").await;

// inside, the execution of the VM is wrapped in `stackful`:
stackful(|| {
  vm.enter_dispatch_loop();
});

// at some point, `sleep` is called:
async fn sleep(scope: Scope<'_>) {
  tokio::time::sleep(1).await;
}

// which would normally cause the VM to yield all the way back up to
// the initial `eval`, but instead, the execution of the native async
// function is wrapped in a `wait` from `stackful`:
impl NativeAsyncFunction {
  fn call(&self, args: Args) -> Result<Value> {
    wait(self(args))
  }
}
@jprochazk jprochazk self-assigned this Jul 8, 2023
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

No branches or pull requests

1 participant