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

Compatible with async/await ? #2638

Closed
varHarrie opened this issue Aug 9, 2016 · 3 comments
Closed

Compatible with async/await ? #2638

varHarrie opened this issue Aug 9, 2016 · 3 comments

Comments

@varHarrie
Copy link

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?

@ilkkao
Copy link

ilkkao commented Aug 9, 2016

That works just fine. In case fun1 or fun2 can throw, you might want to add try/catch

@varHarrie
Copy link
Author

thx a lot : )

@tommoor
Copy link

tommoor commented Apr 20, 2019

For anyone coming via Google, please be aware of this critical issue using await and socket.io:

#3431

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

3 participants