How to parameterize a producer?


#1

The manual on Tasks (aka Coroutines) explains how to create a producer and use it with a Channel.
https://docs.julialang.org/en/latest/manual/control-flow/#man-tasks-1
Then, it says “A common pattern is for the producer to be parameterized, in which case a partial function application is needed to create a 0 or 1 argument anonymous function.”. However, in the example that follows, it is not clear how to bind function mytask(myarg) with a Channel. Where does the Channel parameter in mytask go? How to use such a parameterized producer in a for loop?
I’d appreciate any help!


#2

OK, I think I figured it out. The producer should be defined as producer(c::Channel, myargs) and the Channel should be created with chnl = Channel(c-> producer(c, myargs));
I guess I got confused by mytask(myarg) definition in the example, but it probably only applies to Task objects.
Perhaps the manual could use some clarification :slightly_smiling_face: