Support async methods in the JavaScript kit
Angelmmiguel opened this issue · comments
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