Module: Logster::Deferer

Included in:
Scheduler
Defined in:
lib/logster/scheduler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



5
6
7
# File 'lib/logster/scheduler.rb', line 5

def queue
  @queue
end

#threadObject (readonly)

Returns the value of attribute thread.



5
6
7
# File 'lib/logster/scheduler.rb', line 5

def thread
  @thread
end

Instance Method Details

#disableObject



13
14
15
# File 'lib/logster/scheduler.rb', line 13

def disable
  @enabled = false
end

#enableObject



17
18
19
# File 'lib/logster/scheduler.rb', line 17

def enable
  @enabled = true
end

#initializeObject



6
7
8
9
10
11
# File 'lib/logster/scheduler.rb', line 6

def initialize
  @queue = Queue.new
  @mutex = Mutex.new
  @thread = nil
  @enabled = true
end

#schedule(&blk) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/logster/scheduler.rb', line 21

def schedule(&blk)
  if @enabled
    start_thread if !@thread&.alive?
    @queue << blk
  else
    return if blk == :terminate
    blk.call
  end
end