Class: WonkoTheSane::Util::TaskStack
- Inherits:
-
Object
- Object
- WonkoTheSane::Util::TaskStack
- Defined in:
- lib/wonko_the_sane/util/task_stack.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #in_background(&block) ⇒ Object
-
#initialize ⇒ TaskStack
constructor
A new instance of TaskStack.
- #pop ⇒ Object
- #pop_all ⇒ Object
- #push(task) ⇒ Object
- #push_defered(task) ⇒ Object
Constructor Details
#initialize ⇒ TaskStack
Returns a new instance of TaskStack.
6 7 8 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 6 def initialize @queue = [] end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
4 5 6 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 4 def queue @queue end |
Instance Method Details
#in_background(&block) ⇒ Object
23 24 25 26 27 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 23 def in_background(&block) thread = Thread.new &block pop_all thread.join.value end |
#pop ⇒ Object
16 17 18 19 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 16 def pop task = @queue.pop task.call end |
#pop_all ⇒ Object
20 21 22 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 20 def pop_all pop until @queue.empty? end |
#push(task) ⇒ Object
10 11 12 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 10 def push(task) @queue.push task end |
#push_defered(task) ⇒ Object
13 14 15 |
# File 'lib/wonko_the_sane/util/task_stack.rb', line 13 def push_defered(task) @queue.unshift task end |