Support modules in JavaScript workers
Angelmmiguel opened this issue · comments
Is your feature request related to a problem? Please describe.
At a first approach, the JavaScript workers follow the Web Workers API. It requires to subscribe to a specific event and then, process the request and provide a response:
wasm-workers-server/examples/js-params/fixed.js
Lines 27 to 30 in 51da710
However, the current JavaScript SDK emulates this behavior, so it doesn't provide any Web API behind it. In addition to that, other platforms like Cloudflare and Vercel started to simplify this syntax in favor of ECMA modules:
export default {
async fetch(request) {
const body = `Hello world!`;
return new Response(body);
},
};
This syntax is simpler and more convenient.
Describe the solution you'd like
I want to write workers using the ECMA modules approach, while keeping compatibility with existing modules based on the Web Workers API.
It requires to change the current JavaScript SDK to:
- Manage ECMA modules
- Detect the current approach
- Run the worker to get the response
Describe alternatives you've considered
No response
Additional context
No response