Class: ThreadRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ThreadRunner.rb

Overview

basic thread library

Constant Summary collapse

THREAD_COUNT =
1
MONITORING_TIME =

as second

10

Instance Method Summary collapse

Constructor Details

#initialize(product_func:, thread_func:, thread_count: THREAD_COUNT, monitoring_time: MONITORING_TIME, init_func: -> {}, finish_func: -> {}, main_func: main_thread(), monitor_func: monitor_thread(), product_to_queue_func: products_to_queue()) ⇒ ThreadRunner

Returns a new instance of ThreadRunner.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ThreadRunner.rb', line 6

def initialize (
    product_func: ,
    thread_func: ,
    thread_count:    THREAD_COUNT,
    monitoring_time: MONITORING_TIME,
    init_func:    -> {},
    finish_func:  -> {},
    main_func:    main_thread(),    
    monitor_func: monitor_thread(),
    product_to_queue_func: products_to_queue()
  )
  @thread_func     = thread_func
  @product_func = product_func
  @thread_count    = thread_count
  @monitoring_time = monitoring_time
  @init_func       = init_func
  @finish_func     = finish_func
  @main_thread     = main_func
  @monitor_thread  = monitor_func
  @product_to_queue = product_to_queue_func
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/ThreadRunner.rb', line 28

def run
  @init_func.call

  products = @product_func.call
  queue    = @product_to_queue.call(products)
  @main_thread.call(queue)
  @monitor_thread.call(queue)
  
  @finish_func.call
end