Class: Ocular::DSL::EventBase
- Inherits:
-
Object
- Object
- Ocular::DSL::EventBase
- Defined in:
- lib/ocular/event/eventbase.rb
Defined Under Namespace
Classes: Results
Instance Attribute Summary collapse
-
#proxy ⇒ Object
Returns the value of attribute proxy.
Instance Method Summary collapse
- #__call(context, callback) ⇒ Object
- #exec(context, do_fork = self.proxy.do_fork) ⇒ Object
- #exec_fork(context) ⇒ Object
- #exec_nofork(context) ⇒ Object
-
#initialize(proxy, &block) ⇒ EventBase
constructor
A new instance of EventBase.
Constructor Details
#initialize(proxy, &block) ⇒ EventBase
Returns a new instance of EventBase.
17 18 19 20 |
# File 'lib/ocular/event/eventbase.rb', line 17 def initialize(proxy, &block) @callback = block @proxy = proxy end |
Instance Attribute Details
#proxy ⇒ Object
Returns the value of attribute proxy.
15 16 17 |
# File 'lib/ocular/event/eventbase.rb', line 15 def proxy @proxy end |
Instance Method Details
#__call(context, callback) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ocular/event/eventbase.rb', line 73 def __call(context, callback) # we use this trickery to workaround the LocalJumpError so that we can use return context.define_singleton_method(:_, &callback) p = context.method(:_).to_proc reply = p.call() if context.respond_to?(:exec_wrapper) return context.exec_wrapper(reply) else return reply end end |
#exec(context, do_fork = self.proxy.do_fork) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ocular/event/eventbase.rb', line 22 def exec(context, do_fork = self.proxy.do_fork) start = Time.now begin context.proxy = self.proxy if do_fork return exec_fork(context) else return exec_nofork(context) end ensure context.log_timing("execution_time", start) end end |
#exec_fork(context) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ocular/event/eventbase.rb', line 36 def exec_fork(context) reader, writer = IO::pipe child_pid = fork do reader.close r = Results.new begin r.response = __call(context, @callback) #r.response = context.instance_eval(&@callback) rescue Exception => error r.error = error end response_data = Marshal.dump(r) writer.puts(response_data) writer.close end writer.close data = reader.read r = Marshal.load(data) reader.close Process.wait(child_pid) if r.error raise r.error end return r.response end |
#exec_nofork(context) ⇒ Object
68 69 70 71 |
# File 'lib/ocular/event/eventbase.rb', line 68 def exec_nofork(context) return __call(context, @callback) #context.instance_eval(&@callback) end |