I'm trying to integrate socket.io with koa v2.
Can I pass a async funtion as a event on server side,
just like:
socket.on('message', async () => {
const some1 = await fun1()
const some2 = await fun2()
socket.emit('reply', some1, some2)
...
})
As I known, the async funtion just a wrapper of promise.
Is there any implicit problems?
That works just fine. In case fun1
or fun2
can throw, you might want to add try/catch
thx a lot : )
For anyone coming via Google, please be aware of this critical issue using await
and socket.io:
Most helpful comment
For anyone coming via Google, please be aware of this critical issue using
await
and socket.io:https://github.com/socketio/socket.io/issues/3431