DEV Community

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

Collapse
 
bias profile image
Tobias Nickel

I am not sure if the loops are so much better than registering a listener function. Anyway, If someone prefer an other codestyle it would be easy to implement a single helper method, that takes an Iterable and a callback-function.

However I really thank you showing this project. In has a very interesting architecture. I already installed it and made a first test. because I wanted to know if web-clients can access cross domain. And it worked instandly.

If SocketCluster can hold up to all its promisses, I will have a lot of fun with it.

Thanks for this article.

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.