4 ms·
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 b
by joeycumines 3y ago
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)
- eddtries 3y agoDo 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
- joeycumines 3y agoSure do, I haven't actually used this one (I implemented it just then) but it should do the trick: https://gist.github.com/joeycumines/6206f2a6cd79875c7c16473823ce69de#file-newticker-ts https://gist.github.com/joeycumines/6206f2a6cd79875c7c164738...
- joeycumines 3y agoActually, 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 https://github.com/joeycumines/generator-ticker On NPM as generator-ticker.
- eddtries 3y agoThanks!
- joeycumines 3y agoAddendum: 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.