Class: Rx::ScheduledDisposable

Inherits:
Object
  • Object
show all
Defined in:
lib/rx/subscriptions/scheduled_subscription.rb

Overview

Represents a disposable resource whose disposal invocation will be scheduled on the specified scheduler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheduler, subscription) ⇒ ScheduledDisposable

Returns a new instance of ScheduledDisposable.



9
10
11
12
13
14
15
# File 'lib/rx/subscriptions/scheduled_subscription.rb', line 9

def initialize(scheduler, subscription)
  raise 'disposable cannot be nil' unless subscription
  raise 'scheduler cannot be nil' unless scheduler

  @scheduler = scheduler
  @subscription = subscription
end

Instance Attribute Details

#schedulerObject (readonly)

Returns the value of attribute scheduler.



7
8
9
# File 'lib/rx/subscriptions/scheduled_subscription.rb', line 7

def scheduler
  @scheduler
end

#subscriptionObject (readonly)

Returns the value of attribute subscription.



7
8
9
# File 'lib/rx/subscriptions/scheduled_subscription.rb', line 7

def subscription
  @subscription
end

Instance Method Details

#unsubscribeObject

Unsubscribes the wrapped subscription on the provided scheduler.



23
24
25
26
27
28
29
30
# File 'lib/rx/subscriptions/scheduled_subscription.rb', line 23

def unsubscribe
  @scheduler.schedule lambda do
    unless @subscription.nil?
      @subscription.unsubscribe
      @subscription = nil
    end
  end
end

#unsubscribed?Boolean

Gets a value that indicates whether the object is unsubscribed.

Returns:

  • (Boolean)


18
19
20
# File 'lib/rx/subscriptions/scheduled_subscription.rb', line 18

def unsubscribed?
  @subscription.nil?
end