Here is an example
struct MySubscribable <: Subscribable{Int} end
function Rocket.on_subscribe!(subscribable::MySubscribable, actor)
next!(actor, 1)
next!(actor, 2)
next!(actor, 3)
complete!(actor)
return MyCustomSubscription()
end
struct MyCustomSubscription <: Teardown
# some fields here
end
Rocket.as_teardown(::Type{<:MyCustomSubscription}) = UnsubscribableTeardownLogic()
function Rocket.on_unsubscribe!(subscription::MyCustomSubscription)
# dispose resources here
println("Unsubscribed!")
end
observable = MySubscribable()
my_subscription = subscribe!(observable, logger())
# this will call the on_unsubscribe! method
unsubscribe!(my_subscription)
However if I multicast the observable then the teardown logic is never called
subject = Subject(Int)
observable = MySubscribable() |> multicast(subject)
my_subscription = subscribe!(observable, logger())
connect(observable)
# teardown logic is not called here - why??
unsubscribe!(my_subscription)
Is there any way to force the correct teardown logic to be called when the observable is multicast?