Class: Garcon::ImmediateExecutor

Inherits:
Object
  • Object
show all
Includes:
SerialExecutor
Defined in:
lib/garcon/task/immediate_executor.rb

Overview

Note:

Intended for use primarily in testing and debugging.

An executor service which runs all operations on the current thread, blocking as necessary. Operations are performed in the order they are received and no two operations can be performed simultaneously.

This executor service exists mainly for testing an debugging. When used it immediately runs every ‘#post` operation on the current thread, blocking that thread until the operation is complete. This can be very beneficial during testing because it makes all operations deterministic.

Instance Attribute Summary

Attributes included from Executor

#fallback_policy

Instance Method Summary collapse

Methods included from SerialExecutor

#serialized?

Methods included from Executor

#auto_terminate?, #can_overflow?, #serialized?

Constructor Details

#initializeImmediateExecutor

Creates a new executor



39
40
41
# File 'lib/garcon/task/immediate_executor.rb', line 39

def initialize
  @stopped = Garcon::Event.new
end

Instance Method Details

#<<(task) ⇒ Object



52
53
54
55
# File 'lib/garcon/task/immediate_executor.rb', line 52

def <<(task)
  post(&task)
  self
end

#post(*args, &task) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
# File 'lib/garcon/task/immediate_executor.rb', line 44

def post(*args, &task)
  raise ArgumentError, 'no block given' unless block_given?
  return false unless running?
  task.call(*args)
  true
end

#running?Boolean

Returns:



58
59
60
# File 'lib/garcon/task/immediate_executor.rb', line 58

def running?
  ! shutdown?
end

#shutdownObject Also known as: kill



73
74
75
76
# File 'lib/garcon/task/immediate_executor.rb', line 73

def shutdown
  @stopped.set
  true
end

#shutdown?Boolean

Returns:



68
69
70
# File 'lib/garcon/task/immediate_executor.rb', line 68

def shutdown?
  @stopped.set?
end

#shuttingdown?Boolean

Returns:



63
64
65
# File 'lib/garcon/task/immediate_executor.rb', line 63

def shuttingdown?
  false
end

#wait_for_termination(timeout = nil) ⇒ Object



80
81
82
# File 'lib/garcon/task/immediate_executor.rb', line 80

def wait_for_termination(timeout = nil)
  @stopped.wait(timeout)
end