Class: RxRuby::ScheduledItem
- Inherits:
-
Object
- Object
- RxRuby::ScheduledItem
- Includes:
- Comparable
- Defined in:
- lib/rx_ruby/concurrency/scheduled_item.rb
Overview
Represents a scheduled work item based on the materialization of an scheduler.schedule method call.
Instance Attribute Summary collapse
-
#due_time ⇒ Object
readonly
Returns the value of attribute due_time.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#cancel ⇒ Object
Cancels the work item by disposing the resource returned by invoke_core as soon as possible.
-
#cancelled? ⇒ Boolean
Gets whether the work item has received a cancellation request.
-
#initialize(scheduler, state, due_time, &action) ⇒ ScheduledItem
constructor
A new instance of ScheduledItem.
-
#invoke ⇒ Object
Invokes the work item.
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_ruby/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_time ⇒ Object (readonly)
Returns the value of attribute due_time.
12 13 14 |
# File 'lib/rx_ruby/concurrency/scheduled_item.rb', line 12 def due_time @due_time end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 |
# File 'lib/rx_ruby/concurrency/scheduled_item.rb', line 32 def <=>(other) return @due_time <=> other.due_time end |
#cancel ⇒ Object
Cancels the work item by disposing the resource returned by invoke_core as soon as possible.
37 38 39 |
# File 'lib/rx_ruby/concurrency/scheduled_item.rb', line 37 def cancel @subscription.unsubscribe end |
#cancelled? ⇒ Boolean
Gets whether the work item has received a cancellation request.
23 24 25 |
# File 'lib/rx_ruby/concurrency/scheduled_item.rb', line 23 def cancelled? @subscription.unsubscribed? end |
#invoke ⇒ Object
Invokes the work item.
28 29 30 |
# File 'lib/rx_ruby/concurrency/scheduled_item.rb', line 28 def invoke @subscription.subscription = @action.call @scheduler, @state unless @subscription.unsubscribed? end |