core-async

roklenarcic 2019-12-23T11:23:28.033900Z

what’s the best way to tack on a transducer on to existing channel

roklenarcic 2019-12-23T11:24:03.034600Z

this seems to come up a lot for me… I have a function that returns a channel and I want to add a partition operation to it

roklenarcic 2019-12-23T11:24:31.035200Z

one way is to make a new channel with that transducer and use pipe to move items from one channel to other

roklenarcic 2019-12-23T11:25:05.036Z

I’d love to use pipeline but that seems to consider each item individually in paralel so I don’t know how it plays with the partition operation

2019-12-23T16:32:42.037Z

Yeah pipe is probably your best option if it's not parallel

2019-12-23T16:35:42.039500Z

What's the best way to implement debouce/throttle on a channel? As a custom buffer? A transducer? or a go process? I found a few implementations online but am wondering if it logically belongs in one of these more than the others

fmjrey 2019-12-23T17:08:54.039600Z

Not sure if that matters, but a transducer may be executed on a take or on a put, see https://stackoverflow.com/questions/34847872/how-are-transducers-executed-in-core-async-channels

fmjrey 2019-12-23T17:09:21.039900Z

Also this talk is a good watch if you want to understand the internals: https://vimeo.com/100518968

fmjrey 2019-12-23T17:09:50.040200Z

Slides and transcript links in the comments

fmjrey 2019-12-23T17:13:25.040400Z

you could also make your own channel implementation similar to what kinksy is doing in its duplex channel: https://github.com/pyr/kinsky/blob/a5309073264a1d319d9303a839d9606331560212/src/kinsky/async.clj#L10

2019-12-23T17:14:12.040700Z

cool, thanks for all that!

fmjrey 2019-12-23T17:22:17.040900Z

a few questions for you to ponder about: do you want to throttle on put or on takes? do you want this behaviour to be totally transparent to clients using your channel? which sides or who configures the throttling and how?

fmjrey 2019-12-23T17:24:55.041100Z

oh and are throttling parameters fixed for the duration of the channel or do they need to change during its life?

fmjrey 2019-12-23T17:30:14.041300Z

I'd try first to get by composing existing building blocks: timeout channels, stateful transducers, etc

2019-12-23T20:09:51.041500Z

many of those examples are written before transducers existed btw