Class: DispatchQueue::ThreadQueue
- Inherits:
-
Object
- Object
- DispatchQueue::ThreadQueue
- Includes:
- DispatchAfterImpl, DispatchSyncImpl
- Defined in:
- lib/dispatch_queue_rb/internal/thread_queue.rb
Instance Method Summary collapse
- #dispatch_async(group: nil, &task) ⇒ Object (also: #dispatch_barrier_async)
-
#initialize(thread_termination_delay: 0.01) ⇒ ThreadQueue
constructor
A new instance of ThreadQueue.
Methods included from DispatchAfterImpl
Methods included from DispatchSyncImpl
#dispatch_barrier_sync, #dispatch_sync
Constructor Details
#initialize(thread_termination_delay: 0.01) ⇒ ThreadQueue
Returns a new instance of ThreadQueue.
12 13 14 15 16 17 18 19 |
# File 'lib/dispatch_queue_rb/internal/thread_queue.rb', line 12 def initialize( thread_termination_delay:0.01 ) @thread_termination_delay = thread_termination_delay @mutex = Mutex.new @condition = ConditionVariable.new @tasks = [] @thread = nil end |
Instance Method Details
#dispatch_async(group: nil, &task) ⇒ Object Also known as: dispatch_barrier_async
21 22 23 24 25 26 27 28 29 |
# File 'lib/dispatch_queue_rb/internal/thread_queue.rb', line 21 def dispatch_async( group:nil, &task ) group.enter() if group @mutex.synchronize do resume = @tasks.empty? @tasks << Continuation.new( group:group, &task ) _sync_spawn_or_wakeup_thread() if resume end self end |