Class: Pubby::SimpleAsync
- Inherits:
-
Object
- Object
- Pubby::SimpleAsync
- Defined in:
- lib/pubby/simple_async.rb
Instance Attribute Summary collapse
-
#pubby ⇒ Object
readonly
Returns the value of attribute pubby.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#thread_count ⇒ Object
readonly
Returns the value of attribute thread_count.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
-
#initialize(pubby, thread_count = 1) ⇒ SimpleAsync
constructor
you probably want the pubby used here to be threadsafe if there’s more than one thread…
- #kill! ⇒ Object
- #publish(channel, message) ⇒ Object
- #shutdown! ⇒ Object
Constructor Details
#initialize(pubby, thread_count = 1) ⇒ SimpleAsync
you probably want the pubby used here to be threadsafe if there’s more than one thread…
9 10 11 12 13 14 15 16 |
# File 'lib/pubby/simple_async.rb', line 9 def initialize(pubby, thread_count = 1) @pubby = pubby @thread_count = thread_count @queue = Queue.new @threads = [] start_threads! end |
Instance Attribute Details
#pubby ⇒ Object (readonly)
Returns the value of attribute pubby.
3 4 5 |
# File 'lib/pubby/simple_async.rb', line 3 def pubby @pubby end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
5 6 7 |
# File 'lib/pubby/simple_async.rb', line 5 def queue @queue end |
#thread_count ⇒ Object (readonly)
Returns the value of attribute thread_count.
4 5 6 |
# File 'lib/pubby/simple_async.rb', line 4 def thread_count @thread_count end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
6 7 8 |
# File 'lib/pubby/simple_async.rb', line 6 def threads @threads end |
Instance Method Details
#kill! ⇒ Object
30 31 32 |
# File 'lib/pubby/simple_async.rb', line 30 def kill! @threads.each { |t| t.kill; t.join } end |
#publish(channel, message) ⇒ Object
18 19 20 |
# File 'lib/pubby/simple_async.rb', line 18 def publish(channel, ) @queue << [channel, ] end |
#shutdown! ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/pubby/simple_async.rb', line 22 def shutdown! until @queue.empty? sleep 0.05 end kill! end |