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

Conversion between incomingHandler and request/response #474

Open
peter-jerry-ye opened this issue Jul 26, 2024 · 5 comments
Open

Conversion between incomingHandler and request/response #474

peter-jerry-ye opened this issue Jul 26, 2024 · 5 comments

Comments

@peter-jerry-ye
Copy link
Contributor

Hello,

Since the wasi-http defines a server that accepts an incoming request and returns a response, and jco have the ability to serve a server, is it possible to provide a conversion between the WasiHttpIncomingHandler and a classic JS handlerfetch(request: Request): Promise<Response> (used by e.g. Cloudflare Worker and Deno)? Or should I develop a completely new shim based on the preview2-shim?

@calvinrp
Copy link
Contributor

Hi, I've been working on exactly that. But requires JSPI or Asyncify to handle the asynchronous aspect. Let me know if you are interested in collaborating.

@peter-jerry-ye
Copy link
Contributor Author

@calvinrp Hi, I wonder if it's possible to have a synchronous version MVP? I think the asynchronous might be better supported with WASI Preview 3?

@calvinrp
Copy link
Contributor

calvinrp commented Jul 28, 2024

@peter-jerry-ye I do have sync implementation working just for the incoming response handler, but limited to that.

If you want to do outbound requests or many things that rely upon wasi:io/poll or wasi:io/streams, then you will need async support.

The issue is the JS APIs that you need to use are async but the Wasm functions are sync (in WASI P2). There a few different ways to go about this. JSPI (JavaScript Promise Integration), which is a stack switching proposal, is the ideal implementation. It is behind a feature flag in V8 and expected to be released before the end of year. Asyncify requires a rewrite of the Wasm binary but could be used as a stop gap. Using Atomics and Web Workers is also helpful in some circumstances. Also, to a limited degree there is a path with synchronous XHR, Web Workers and Service Workers.

@peter-jerry-ye
Copy link
Contributor Author

@calvinrp Thank you very much for your kind explanation. I see that jco server seems to be using Web Workers to solve this issue.

@calvinrp
Copy link
Contributor

Happy to update on progress. It sounds like what I'm working on will be useful to you.

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

2 participants