Closed vegabook closed 5 years ago
The behavior is controlled by the :cancel option given to sync_subscribe. Note that cancel is not routed through the consumer, so the consumer doesn’t know it will be cancelled, that’s why it doesn’t treat it in any special way. From the perspective of the consumer, it is a cancellation as any other. --
José Valim www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D
Also note the atom given to cancel is the cancellation reason. You likely want to set it to shutdown and pass cancel: :transient on sync_subscribe. --
José Valim www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D
Okay I think I did that, but maybe I misunderstood because something still seems to be going wrong. My producer-consumer that consumes from producer still shuts down when I close the subscription between them.
The second argument to cancel should be the atom :shutdown. I.e. it is the cancellation reason. --
José Valimwww.plataformatec.com.br http://www.plataformatec.com.br/Founder and Director of R&D
aha! it works! apologies for disturbing. Not sure this is well documented? Docs seem only to give options :noconnect and :nosuspend.
I will take a look at the docs! --
José Valimwww.plataformatec.com.br http://www.plataformatec.com.br/Founder and Director of R&D
I'm using
GensStage.sync_subscribe
to get a consumer to connect to a producer-consumer. Later I want to cancel the subscription, but I'd still like to use the consumer later. However using GenStage.cancel seems to kill both the subscription and the associated consumer.Herewith some code, assuming GenStage already specified in mix.exs. This can be pasted wholesale into IEX, but you must first change @filename in GenstageTest.Consumer to something that will work on your computer. Then "touch
filename
", and "tail -Ffilename
" in another terminal. This will avoid all the output swarming into iex.So now what you see a sequence of incrementing numbers being produced in the terminal where you ran tail -F.
Now whether I use
GenStage.cancel({p, link1}, :noconnect)
orGenStage.cancel({p, link1}, :nosuspend)
, it will stop the subscription, but also kills my producer-consumer (GenstageTest.pcAddOne).Surely it's supposed to cancel the subscription, but not kill the consumer at the same time? Is this a bug? Or is there another technique I should use to reach the objective only of desubscribing without ending the consumer?