2 ms·
Callbacks (including those passed to Promise then methods) are a dangerous primitive. I would recommend using awaitable streams like those used in https://socke
by applepple 6y ago
Callbacks (including those passed to Promise then methods) are a dangerous primitive. I would recommend using awaitable streams like those used in https://socketcluster.io/ https://socketcluster.io/ - Or https://github.com/SocketCluster/writable-consumable-stream https://github.com/SocketCluster/writable-consumable-stream for general purpose.
The philosophy of SC and WritableConsumableStream is that the main trunk logic of your system/module should declared as a single serial stream and any parallel logic should explicitly branch off from it.
With traditional event listeners, there is no such thing as a 'main trunk' of the logic... The entry points (event listeners) are scattered all over the place and this can cause a lot of possible state permutations when business logic is executed inside those listeners (since you can't control the timing of when those event handlers are called).
This kind of programming is a good alternative to functional programming as it offers a safe way to asynchronously mutate state.
- hyeomans 6y agoNice, are you using it in production? First time I hear about SocketCluster