Module: Tribe::Actable
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #enqueue(command, data = nil) ⇒ Object
- #enqueue_future(command, data = nil) ⇒ Object
- #identifier ⇒ Object
- #name ⇒ Object
- #perform(&block) ⇒ Object
- #shutdown ⇒ Object
Instance Method Details
#alive? ⇒ Boolean
70 71 72 |
# File 'lib/tribe/actable.rb', line 70 def alive? @_as.mailbox.synchronize { return @_as.alive } end |
#enqueue(command, data = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/tribe/actable.rb', line 39 def enqueue(command, data = nil) return false unless alive? @_as.mailbox.push(Workers::Event.new(command, data)) do @_as.pool.perform { process_events } end return true end |
#enqueue_future(command, data = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tribe/actable.rb', line 49 def enqueue_future(command, data = nil) @_as.futures ||= Tribe::SafeSet.new # Lazy instantiation for performance. future = Tribe::Future.new @_as.futures.add(future) perform do begin result = event_handler(Workers::Event.new(command, data)) future.result = result rescue Exception => exception future.result = exception raise ensure @_as.futures.delete(future) end end return future end |
#identifier ⇒ Object
78 79 80 |
# File 'lib/tribe/actable.rb', line 78 def identifier return @_as.name ? "#{object_id}:#{@_as.name}" : object_id end |
#name ⇒ Object
74 75 76 |
# File 'lib/tribe/actable.rb', line 74 def name return @_as.name end |
#perform(&block) ⇒ Object
86 87 88 |
# File 'lib/tribe/actable.rb', line 86 def perform(&block) return enqueue(:perform, block) end |
#shutdown ⇒ Object
82 83 84 |
# File 'lib/tribe/actable.rb', line 82 def shutdown return enqueue(:shutdown) end |