Class: EnumeratorConcurrent::Threaded
- Defined in:
- lib/enumerator_concurrent/threaded.rb
Overview
Each Iteration in an own Thread. Less overhead then Queued
Instance Method Summary collapse
-
#each(&block) ⇒ Array
As the standard each does.
-
#each_to_thread ⇒ Array<thread>
initializes for every iteration a new Thread.
-
#join_threads ⇒ Array<thread.join.value>
joins a list of threads and returns the threads value.
- #threads(thread_workers) ⇒ Enumerator::ConcurrentQueue
Methods inherited from Array
Instance Method Details
#each(&block) ⇒ Array
Returns as the standard each does.
7 8 9 |
# File 'lib/enumerator_concurrent/threaded.rb', line 7 def each(&block) each_to_thread(&block).join_threads end |
#each_to_thread ⇒ Array<thread>
initializes for every iteration a new Thread
19 20 21 |
# File 'lib/enumerator_concurrent/threaded.rb', line 19 def each_to_thread Threaded.new map { |x| Thread.new { yield(x) } } end |
#join_threads ⇒ Array<thread.join.value>
joins a list of threads and returns the threads value
13 14 15 |
# File 'lib/enumerator_concurrent/threaded.rb', line 13 def join_threads Threaded.new map { |x| x.join.value } end |
#threads(thread_workers) ⇒ Enumerator::ConcurrentQueue
25 26 27 |
# File 'lib/enumerator_concurrent/threaded.rb', line 25 def threads(thread_workers) Queued.new self, thread_workers end |