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

Support async methods in the JavaScript kit #142

Closed
Angelmmiguel opened this issue May 29, 2023 · 0 comments · Fixed by #143
Closed

Support async methods in the JavaScript kit #142

Angelmmiguel opened this issue May 29, 2023 · 0 comments · Fixed by #143
Assignees
Labels
🚀 enhancement New feature or request
Milestone

Comments

@Angelmmiguel
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, the JavaScript workers don't allow you to use async methods for handlers. In some cases, this is convenient as the methods may need to wait for some resources before returning the response. Async methods are supported since Javy 1.0.0, so we should be able to implement them in wws.

This is an example of an async worker:

// Using an async function to reply!
async function handle(request) {
  // Body response
  const body = `Hello world!`;

  // Build a new response
  let response = new Response(body);

  // Add a new header
  response.headers.set("x-generated-by", "wasm-workers-server");

  return response;
}

addEventListener('fetch', event => {
  event.respondWith(handle(event.request));
});

Even though it doesn't require an async method, we can use it as an example.

Describe the solution you'd like

I would like to use async when defining methods in JavaScript workers. Some libraries and several examples that I found require this feature.

It's available in Javy 1.0.0, so it may require to upgrade the JavaScript kit and start using the new crate from the Javy team: https://crates.io/crates/javy.

Describe alternatives you've considered

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant