News for hackers. Stuff that matters.
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by eddtries on Monday November 06, 2023 @02:50AM (#38159858)
The thing that made me love Golang was the Time channel, where you can have a channel execute a function every X milliseconds, without having to worry about blocking threads with time.sleep() etc. It made a lot of stuff I wanted to write so much easier I basically went all in on Go and haven't regretted it.
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Monday November 06, 2023 @03:07AM (#38159944)
That one is actually pretty easy in JavaScript - in the past I've implemented the same sort of behavior using async generators.

(I also like Go's time.Ticker behavior quite a lot)

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by eddtries on Monday November 06, 2023 @12:21PM (#38165495)
Do you have an example? For my case it was an internal lambda service that could add functions with specific intervals to the time.Ticker match, basically you edit a config to add a path to an executable and an interval and then I added it to my script
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Wednesday November 08, 2023 @05:13AM (#38188537)
Sure do, I haven't actually used this one (I implemented it just then) but it should do the trick: https://gist.github.com/joeycumines/6206f2a6cd79875c7c164738...
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Wednesday November 08, 2023 @09:51AM (#38191138)
Actually, it was fun, so I've made it into an actual package.

The one I slapped together works, but this one is better (fixes issues with actually stopping it properly): https://github.com/joeycumines/generator-ticker

On NPM as generator-ticker.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by eddtries on Wednesday November 08, 2023 @11:26AM (#38192697)
Thanks!
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by joeycumines on Wednesday November 08, 2023 @09:24PM (#38200278)
Addendum: My first attempt would drift over time, if the receiver was slow.

Hurt my head a little, but it's fixed now, and I'm at least moderately confident it's correct - unit tested the behavior step by step using `ts-chan`, actually. Will probably use that test as another example use case.

Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by penneallagricia on Monday November 06, 2023 @04:07AM (#38160282)
How is it different from setInterval in JS?
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by vanderZwan on Monday November 06, 2023 @04:12AM (#38160326)
Technically speaking? Go has parallelism by default, I suppose. But if your functions take negligible time to execute and the interval is sufficiently large enough then nothing from a user perspective.
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by eddtries on Monday November 06, 2023 @11:56AM (#38165115)
Yeah I was designing an internal lambda server so mostly parallelism, all I had to do was have a dynamic match and everything else was out the box for the load I needed
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by vanderZwan on Monday November 06, 2023 @01:35PM (#38166720)
Yeah, I'm sure a well-written parallel Rust or C++ program (using just the CPU cores) can do better, but Go really hits a Pareto sweet spot in terms of "effort vs speedup" return on investment.
Re:Show HN: Ts-Chan – Go-Like Concurrency Primitives for Typ... by eddtries on Wednesday November 08, 2023 @11:28AM (#38192736)
I’m not the best systems dev, when I get these options I pick easy!