DEV Community

Discussion on: SocketCluster. The most underrated framework. Part 3: A Pub/Sub example and middleware

Collapse
 
maartennnn profile image
maarteNNNN

Thanks for your reply and insight!

I have covered the benefit of the async iterables briefly in part 1. It's basically queuing actions. This is more advantageous than callbacks that do not care about concurrent logic. An example I gave is that database operations will execute according to the queue. Event listeners actions run concurrently, and therefore could potentially generate errors. Upon talking to the creator of SocketCluster, Jon Dubois, he said that in previous versions of the framework - which did not utilize the async iterable, that it was the most common problem.

As for syntax the (async => { ... })() is indeed not a very beautiful syntax. It can be easily forgotten to execute it by adding the (), overall it needs a ; to be able to format it with Prettier for example. However there are some proposals to ECMAScript to resolve these issues. One of them is the async do proposal. Another is top-level await.