Class: RubyJard::ReplProxy::ReplState
- Inherits:
-
Object
- Object
- RubyJard::ReplProxy::ReplState
- Defined in:
- lib/ruby_jard/repl_proxy.rb
Overview
A class to store the state with multi-thread guarding Ready => Processing/Exiting Processing => Ready again Exiting => Exited Exited => Ready
Constant Summary collapse
- STATES =
[ STATE_READY = 0, STATE_EXITING = 1, STATE_PROCESSING = 2, STATE_EXITED = 3 ].freeze
Instance Method Summary collapse
- #check(method_name) ⇒ Object
- #exited! ⇒ Object
- #exited? ⇒ Boolean
- #exiting! ⇒ Object
- #exiting? ⇒ Boolean
-
#initialize ⇒ ReplState
constructor
A new instance of ReplState.
- #processing! ⇒ Object
- #processing? ⇒ Boolean
- #ready! ⇒ Object
- #ready? ⇒ Boolean
Constructor Details
#initialize ⇒ ReplState
Returns a new instance of ReplState.
80 81 82 83 |
# File 'lib/ruby_jard/repl_proxy.rb', line 80 def initialize @state = STATE_EXITED @mutex = Mutex.new end |
Instance Method Details
#check(method_name) ⇒ Object
85 86 87 |
# File 'lib/ruby_jard/repl_proxy.rb', line 85 def check(method_name) @mutex.synchronize { yield if send(method_name) } end |
#exited! ⇒ Object
121 122 123 |
# File 'lib/ruby_jard/repl_proxy.rb', line 121 def exited! @mutex.synchronize { @state = STATE_EXITED } end |
#exited? ⇒ Boolean
117 118 119 |
# File 'lib/ruby_jard/repl_proxy.rb', line 117 def exited? @state == STATE_EXITED end |
#exiting! ⇒ Object
113 114 115 |
# File 'lib/ruby_jard/repl_proxy.rb', line 113 def exiting! @mutex.synchronize { @state = STATE_EXITING } end |
#exiting? ⇒ Boolean
109 110 111 |
# File 'lib/ruby_jard/repl_proxy.rb', line 109 def exiting? @state == STATE_EXITING end |
#processing! ⇒ Object
103 104 105 106 107 |
# File 'lib/ruby_jard/repl_proxy.rb', line 103 def processing! return unless ready? @mutex.synchronize { @state = STATE_PROCESSING } end |
#processing? ⇒ Boolean
99 100 101 |
# File 'lib/ruby_jard/repl_proxy.rb', line 99 def processing? @state == STATE_PROCESSING end |
#ready! ⇒ Object
93 94 95 96 97 |
# File 'lib/ruby_jard/repl_proxy.rb', line 93 def ready! if ready? || processing? || exited? @mutex.synchronize { @state = STATE_READY } end end |
#ready? ⇒ Boolean
89 90 91 |
# File 'lib/ruby_jard/repl_proxy.rb', line 89 def ready? @state == STATE_READY end |