-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fiber/fasthttp support #18
Comments
Hi @pjebs This would be a great improvement indeed. fasthttp uses a completely different API from net/http so this would need some work. However here are some thoughts after having looked at
|
You don't seem to be using |
Yes, the dependency to |
I wonder if there was a way to run wasm server on a web worker and have something else simpler intercept the fetch on the service worker and communicate with web worker. Web workers are better suited for long running tasks. |
Maybe we should think about this in relation to Cloudflare pages too. The golang wasm for that has its own http driver too. https://github.com/syumai/workers Uses compiler tags .. https://github.com/syumai/workers/blob/main/handler_js.go being the tag for wasm. https://github.com/syumai/workers/blob/main/handler.go being the tag for normal non wasm. —- As far as browser web workers go yes it’s 100% possible. https://github.com/magodo/go-wasmww/tree/main/examples/dedicated I need to fork and make changes for go 1.24. Will use build tags to keep it working on previous go versions |
@gedw99 cloudflare uses standard golang net/http |
Seems its using this for requests: https://github.com/syumai/workers/blob/main/internal/jshttp/request.go for the wasm which does import the “http” , but has a few customisations for Cloud flare. |
That is just a function to convert JS request objects to net/http request objects and vice-versa |
go-wasm-http-server’s primary goal is to hook Go’s HTTP framework to the Service Worker’s fetch events. As I understand it, Web Workers are useful when there is the need to run CPU heavy tasks without impacting the user interface, or in other words the run loop, which is slightly different. HTTP requests may trigger heavy tasks, but I don’t think this should fall under go-wasm-http-server’s scope, as it is not generally the case. If one needs to run heavy tasks in a Go WASM binary, I think a better suited approach would be to run a goroutine in a Web Worker, and right some code or even a library to achieve this. |
@nlepage I was thinking more along the lines of WASM running on web worker being long-lasting and not getting shut-down or suspended like service workers are prone to: https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle and mswjs/msw#2115 I actually got it to work as a proof-of-concept. You need 2 Unfortunately there is a limit on the type of data that can pass those boundaries. You can't send a JS Request or Response object past those boundaries because they are either not "transportable" or don't satisfy the In your code, since the WASM server and Service worker are within the same context, the server can stream data etc very easily. That would be much harder to do when the WASM server is not in the same context as the service worker. It can be done however: https://github.com/whatwg/streams/blob/main/transferable-streams-explainer.md and https://github.com/MattiasBuelens/remote-web-streams |
Fasthttp is an alternative http server package that is substantially faster.
This would be great if it supports that.
The text was updated successfully, but these errors were encountered: