DEV Community

[Comment from a deleted post]
Collapse
 
erebos-manannan profile image
Erebos Manannán

I hate it when people post example code with obvious bad design flaws, as people are going to take your code, copy & paste it, fiddle with it, and release it into production without understanding half of what's going on.

It seems like you're initializing a new interval for every connected client, which ends up with you making separate API calls for every connected client instead of you having a global interval and distributing the results to all connected clients.

Additionally you're never stopping the interval, so you're leaking memory and worst of all causing a huge amount of API calls to be made when someone just hits F5 a few times.

Collapse
 
valentinogagliardi profile image
Valentino Gagliardi

It should be clear that the article is merely intended as an example from where the reader should start experimenting on his own.

Also, the code is not intended to be used from multiple client as it is, obviously you should clear the interval if you were to handle multiple connections.

I write my articles with simplicity in mind and maybe I took for granted that some reader won't simply copy the code and past it into a production app.

By the way, thanks for pointing this out, I'll add a note to clarify the problem.