Module: Zoidberg::HardShell
- Defined in:
- lib/zoidberg/shell.rb
Overview
Confined proxy based shell
Defined Under Namespace
Classes: AsyncProxy
Class Method Summary collapse
Instance Method Summary collapse
-
#async(locked = false, &block) ⇒ AsyncProxy, NilClass
Perform an async action.
-
#defer { ... } ⇒ Object
Unlock current lock on instance and execute given block without locking.
-
#sleep(length = nil) ⇒ Float
Provide a customized sleep behavior which will unlock the real instance while sleeping.
Class Method Details
Instance Method Details
#async(locked = false, &block) ⇒ AsyncProxy, NilClass
Perform an async action
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/zoidberg/shell.rb', line 167 def async(locked=false, &block) if(block) if(locked) current_self.instance_exec(&block) else current_self._async_request(locked ? :blocking : :nonblocking, :instance_exec, &block) end else ::Zoidberg::HardShell::AsyncProxy.new(current_self, locked) end end |
#defer { ... } ⇒ Object
Unlock current lock on instance and execute given block without locking
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/zoidberg/shell.rb', line 149 def defer(&block) if(current_self.threaded?) action = Task.new(:async, current_self){ block.call } current_self.task_defer(action) Thread.stop action.value else Fiber.yield if(block) ::Fiber.new(&block).resume end end end |
#sleep(length = nil) ⇒ Float
Provide a customized sleep behavior which will unlock the real instance while sleeping
184 185 186 187 188 189 190 191 192 |
# File 'lib/zoidberg/shell.rb', line 184 def sleep(length=nil) start_time = ::Time.now.to_f if(length) defer{ ::Kernel.sleep(length) } else ::Thread.current[:root_fiber] == ::Fiber.current ? ::Kernel.sleep : ::Fiber.yield end ::Time.now.to_f - start_time end |