Class: Garcon::ImmediateExecutor
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
#serialized?
Methods included from Executor
#auto_terminate?, #can_overflow?, #serialized?
Constructor Details
39
40
41
|
# File 'lib/garcon/task/immediate_executor.rb', line 39
def initialize
@stopped = Garcon::Event.new
end
|
Instance Method Details
52
53
54
55
|
# File 'lib/garcon/task/immediate_executor.rb', line 52
def <<(task)
post(&task)
self
end
|
#post(*args, &task) ⇒ Object
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
|
58
59
60
|
# File 'lib/garcon/task/immediate_executor.rb', line 58
def running?
! shutdown?
end
|
#shutdown ⇒ Object
Also known as:
kill
73
74
75
76
|
# File 'lib/garcon/task/immediate_executor.rb', line 73
def shutdown
@stopped.set
true
end
|
68
69
70
|
# File 'lib/garcon/task/immediate_executor.rb', line 68
def shutdown?
@stopped.set?
end
|
#shuttingdown? ⇒ Boolean
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
|