moroshko
moroshko
Explore posts from servers
HHono
Created by moroshko on 10/25/2024 in #help
How to perform an async operation in Web Socket's onMessage?
I'm using Web Sockets with Bun, and wondering what's the idiomatic Hono-way of awaiting a Promise in onMessage (which is a sync method)?
const { upgradeWebSocket, websocket } = createBunWebSocket<ServerWebSocket>();

new Hono().get(
"/",
upgradeWebSocket((c) => {
return {
onMessage(event, ws) { // not async :(
// How can await here something, e.g. await Bun.sleep(10);
},
...
}
})
)
const { upgradeWebSocket, websocket } = createBunWebSocket<ServerWebSocket>();

new Hono().get(
"/",
upgradeWebSocket((c) => {
return {
onMessage(event, ws) { // not async :(
// How can await here something, e.g. await Bun.sleep(10);
},
...
}
})
)
I tried to use setTimeout and Promise.then(), but their callbacks are never executed.
2 replies