cah4a / trpc-bun-adapter

Use tRPC with bun and fun
https://www.npmjs.com/package/trpc-bun-adapter
MIT License
42 stars 8 forks source link

createBunWsHandler handleRequest race problem #11

Closed motopods-lucas closed 3 weeks ago

motopods-lucas commented 2 months ago

websocket

-----> open

https://github.com/cah4a/trpc-bun-adapter/blob/4de96b72e099c4d19561651bc43b74c8fc3240ec/src/createBunWSHandler.ts#L79 await ctxPromise; // if this takes some time.

----> message https://github.com/cah4a/trpc-bun-adapter/blob/4de96b72e099c4d19561651bc43b74c8fc3240ec/src/createBunWSHandler.ts#L290

    const promises = msgs
        .map((raw) =>
            parseTRPCMessage(raw, router._def._config.transformer),
        )
        .map(client.data.handleRequest); // client.data.handleRequest is no ready yet, so there is an error TypeError: Array.prototype.map callback must be a function.

https://github.com/cah4a/trpc-bun-adapter/blob/4de96b72e099c4d19561651bc43b74c8fc3240ec/src/createBunWSHandler.ts#L125 client.data.handleRequest = ... // set handleRequest

motopods-lucas commented 2 months ago

Make a PR https://github.com/cah4a/trpc-bun-adapter/pull/12

cah4a commented 3 weeks ago

Thanks for your contributing!

Packaged version 1.2.0 is available now.

There more fixes, please double check on your case and re-open issue if reproduces.