Module: Zoidberg::SoftShell
- Included in:
- Pool, Registry, Signal, Supervisor, Timer
- Defined in:
- lib/zoidberg/shell.rb
Overview
Librated 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
.included(klass) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/zoidberg/shell.rb', line 158 def self.included(klass) unless(klass.include?(::Zoidberg::Shell)) klass.class_eval do include ::Zoidberg::Shell end end end |
Instance Method Details
#async(locked = false, &block) ⇒ AsyncProxy, NilClass
Perform an async action
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/zoidberg/shell.rb', line 86 def async(locked=false, &block) if(block_given?) unless(locked) _zoidberg_proxy._thread_pool << lambda{ begin self.instance_exec(&block) rescue Zoidberg::DeadException => e if(e.origin_object_id == object_id) raise else _zoidberg_proxy._zoidberg_unexpected_error(e) raise end rescue ::StandardError, ::ScriptError => e _zoidberg_proxy._zoidberg_unexpected_error(e) raise end } else _zoidberg_proxy._thread_pool << lambda{ _zoidberg_proxy._aquire_lock! begin got_lock = true self.instance_exec(&block) rescue Zoidberg::DeadException => e if(e.origin_object_id == object_id) got_lock = false else _zoidberg_proxy._zoidberg_unexpected_error(e) end raise rescue ::StandardError, ::ScriptError => e _zoidberg_proxy._zoidberg_unexpected_error(e) raise ensure _zoidberg_proxy._release_lock! if got_lock end } end nil else ::Zoidberg::SoftShell::AsyncProxy.new(locked, _zoidberg_proxy) end end |
#defer { ... } ⇒ Object
Unlock current lock on instance and execute given block without locking
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/zoidberg/shell.rb', line 67 def defer re_lock = _zoidberg_proxy._release_lock! begin result = yield if block_given? result rescue ::Zoidberg::DeadException => e re_lock = false if e.origin_object_id == object_id raise rescue ::StandardError, ::ScriptError => e raise e ensure _zoidberg_proxy._aquire_lock! if re_lock end end |
#sleep(length = nil) ⇒ Float
Provide a customized sleep behavior which will unlock the real instance while sleeping
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/zoidberg/shell.rb', line 136 def sleep(length=nil) if(_zoidberg_proxy._locker == ::Thread.current) defer do start_time = ::Time.now.to_f if(length) ::Kernel.sleep(length) else ::Kernel.sleep end ::Time.now.to_f - start_time end else start_time = ::Time.now.to_f if(length) ::Kernel.sleep(length) else ::Kernel.sleep end ::Time.now.to_f - start_time end end |