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
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/zoidberg/shell.rb', line 218 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
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/zoidberg/shell.rb', line 200 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
235 236 237 238 239 240 241 242 243 |
# File 'lib/zoidberg/shell.rb', line 235 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 |