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.



3
4
5
# File 'lib/logster/scheduler.rb', line 3

def queue
  @queue
end

#threadObject (readonly)

Returns the value of attribute thread.



3
4
5
# File 'lib/logster/scheduler.rb', line 3

def thread
  @thread
end

Instance Method Details

#disableObject



11
12
13
# File 'lib/logster/scheduler.rb', line 11

def disable
  @enabled = false
end

#enableObject



15
16
17
# File 'lib/logster/scheduler.rb', line 15

def enable
  @enabled = true
end

#initializeObject



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

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

#schedule(&blk) ⇒ Object



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

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