TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Usefulness of Abstracting Over Time

53 pointsby maxhallinanalmost 7 years ago

4 comments

orfalmost 7 years ago
I get why removing global state is a good thing in general, but here you are replacing it with a whole lot of complexity for not a particularly clear reason. Is tracking the user count with an integer dangerous <i>in this case</i> (Have you run into problems with it)? Is your solution not using global state anyway, just wrapped in a library?<p>All in all, are the abstractions (a bunch of new concepts plus a new library) <i>worth it</i> to just replace an integer?<p><pre><code> function timerFunc() { if (connectionCounter) get results(); } socket.on(&#x27;connect&#x27;, function() { connectCounter++; }); socket.on(&#x27;disconnect&#x27;, function() { connectCounter--; }); </code></pre> The real problem is you want to start and stop the timer when someone connects. Just keep it simple and keep it going, but not doing anything if there is nobody connected, like above.
评论 #17792207 未加载
mpweiheralmost 7 years ago
Hmm...<p>&quot;The server always asks for new location data, every 30 seconds, even when no one is listening.&quot;<p>...<p>&quot;Our task is to pause the timer when there are no websocket connections and start the timer when a client connects.&quot;<p>That sounds like asking for trouble. Maybe there&#x27;s something I am not understanding, but why not have the timer run continuously and have the timer <i>action</i> check whether it needs to request location data?<p>Yes, that will cause the process to wake up every 30 seconds even if there is no action, but unless circumstances are very special that won&#x27;t be a significant problem.
评论 #17790282 未加载
评论 #17790096 未加载
评论 #17790094 未加载
wilgertvelingaalmost 7 years ago
Very nice explanation. Gives a good insight how you can &quot;think in observables&quot;. Two small things 1. instead of merging zero$ into connectionClosed$ you can use the startWith() method. 2. Instead of using the head method to pluck the first item of an array you could use array destructuring. (But I can understand that you wouldn&#x27;t do it in this to limit the amount of &quot;new&quot; concepts)
fleitzalmost 7 years ago
Send a message to a queue asking for refreshed data... ignore messages that occur within a given timeframe.<p>Or put your server in front of a CDN &#x2F; Nginx, set cache headers for 30 seconds ;)