class RxRuby::CompositeSubscription
Represents a group of subscription resources that are unsubscribed together.
Attributes
length[R]
Public Class Methods
new(subscriptions = [])
click to toggle source
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 14 def initialize(subscriptions = []) @subscriptions = subscriptions @length = subscriptions.length @unsubscribed = false @gate = Mutex.new end
Public Instance Methods
clear()
click to toggle source
Removes and unsubscribes all subscriptions from the CompositeSubscription
, but does not dispose the CompositeSubscription
.
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 66 def clear currentSubscriptions = nil @gate.synchronize do currentSubscriptions = @subscriptions @subscriptions = [] @length = 0 end currentSubscriptions.each {|subscription| subscription.unsubscribe} end
delete(subscription)
click to toggle source
Removes and unsubscribes the first occurrence of a subscription from the CompositeSubscription
.
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 78 def delete(subscription) should_unsubscribe = nil @gate.synchronize do should_unsubscribe = @subscriptions.delete(subscription) @length -= 1 if should_unsubscribe end subscription.unsubscribe if should_unsubscribe should_unsubscribe end
each(&block)
click to toggle source
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 26 def each(&block) @subscriptions.each(&block) end
push(subscription)
click to toggle source
Adds a subscription to the CompositeSubscription
or unsubscribes the subscription if the CompositeSubscription
is unsubscribed.
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 47 def push(subscription) should_unsubscribe = false @gate.synchronize do should_unsubscribe = @unsubscribed unless @unsubscribed @subscriptions.push(subscription) @length += 1 end end subscription.unsubscribe if should_unsubscribe return self end
Also aliased as: <<
unsubscribe()
click to toggle source
Unsubscribes all subscriptions in the group and removes them from the group.
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 31 def unsubscribe currentSubscriptions = nil @gate.synchronize do unless @unsubscribed @unsubscribed = true currentSubscriptions = @subscriptions @subscriptions = [] @length = 0 end end currentSubscriptions.each {|subscription| subscription.unsubscribe} if currentSubscriptions end
unsubscribed?()
click to toggle source
Gets a value that indicates whether the object is unsubscribed.
# File lib/rx_ruby/subscriptions/composite_subscription.rb, line 22 def unsubscribed? @unsubscribed end