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

Class Method Details

.included(klass) ⇒ Object



172
173
174
175
176
177
178
# File 'lib/zoidberg/shell.rb', line 172

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



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/zoidberg/shell.rb', line 145

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

Yields:

  • block to execute without lock



134
135
136
137
138
139
# File 'lib/zoidberg/shell.rb', line 134

def defer(&block)
  Fiber.yield
  if(block)
    ::Fiber.new(&block).resume
  end
end

#sleep(length = nil) ⇒ Float

Provide a customized sleep behavior which will unlock the real instance while sleeping



162
163
164
165
166
167
168
169
170
# File 'lib/zoidberg/shell.rb', line 162

def sleep(length=nil)
  start_time = ::Time.now.to_f
  if(length)
    ::Kernel.sleep(length)
  else
    ::Thread.current[:root_fiber] == ::Fiber.current ? ::Kernel.sleep : ::Fiber.yield
  end
  ::Time.now.to_f - start_time
end