Class: Rx::ScheduledItem

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rx/concurrency/scheduled_item.rb

Overview

Represents a scheduled work item based on the materialization of an scheduler.schedule method call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheduler, state, due_time, &action) ⇒ ScheduledItem

Returns a new instance of ScheduledItem.



14
15
16
17
18
19
20
# File 'lib/rx/concurrency/scheduled_item.rb', line 14

def initialize(scheduler, state, due_time, &action)
  @scheduler = scheduler
  @state = state
  @action = action
  @due_time = due_time
  @subscription = SingleAssignmentSubscription.new
end

Instance Attribute Details

#due_timeObject (readonly)

Returns the value of attribute due_time.



12
13
14
# File 'lib/rx/concurrency/scheduled_item.rb', line 12

def due_time
  @due_time
end

Instance Method Details

#<=>(other) ⇒ Object



32
33
34
# File 'lib/rx/concurrency/scheduled_item.rb', line 32

def <=>(other)
  return @due_time <=> other.due_time
end

#cancelObject

Cancels the work item by disposing the resource returned by invoke_core as soon as possible.



37
38
39
# File 'lib/rx/concurrency/scheduled_item.rb', line 37

def cancel
  @subscription.unsubscribe
end

#cancelled?Boolean

Gets whether the work item has received a cancellation request.

Returns:

  • (Boolean)


23
24
25
# File 'lib/rx/concurrency/scheduled_item.rb', line 23

def cancelled?
  @subscription.unsubscribed?
end

#invokeObject

Invokes the work item.



28
29
30
# File 'lib/rx/concurrency/scheduled_item.rb', line 28

def invoke
  @subscription.subscription = @action.call @scheduler, @state unless @subscription.unsubscribed?
end