Here’s a question about Channel
s - I read @oxinabox great introductions to Channels, and I’m considering a use case for them. I have some code that randomizes a Matrix. There’s some preprocessing going on, and the matrices are rather large, so I thought this might be a use case - you never want to have more in memory than the single one, and then call a new one - and the preprocessing might happen when starting the Channel.
So, you’d have an object rmc = RandomMatrixChannel(mymatrix)
, and then call take!(rmc, 1)
whenever you need a new Matrix.
Another way of doing this would be to make a Generator object where the constructor did the preprocessing, and then have that object be callable - rmg = RandomMatrixGenerator(mymatrix); rmg()
. That might be less strange for a user - this is for user-facing code in a package.
My question is: is this a good usecase for a channel? And what’s the main difference in the behaviour of these two approaches? Will the buffering done by the channel allow something to go on in the background so to speak, and thus be more efficient?