Reputation: 21062
var sub = observable.Subscribe(data => my_action(data));
When I dispose the sub
variable it will unsubscribe. Ok, but when doing so will it wait for my_action
to end if it was already called?
Update 1: I ask for conscious decision, not some side-effects. Compare this to Threading.Timer -- in order to wait for action you have to call special Dispose
method.
Update 2: I ask for waiting for action to end, not to cancel the action.
Upvotes: 2
Views: 144
Reputation: 14350
If your question is, will subscription-disposal ever cancel an action triggered by a prior observation, the answer is no.
EDIT:
To answer your clarified question, the short answer is no. Disposal is scheduled immediately. Depending on your thread/scheduler situation, it will then either be executed immediately, or executed when there's an availaible thread.
Upvotes: 3
Reputation: 16086
It depends. If the action and the dispose occur on the same thread, then the disposal will happen after the action completes. If the action runs on a different thread to the disposal then they occur independently and it is possible for the disposal to occur while action is executing.
Upvotes: 3