Class: Rubish::BatchExecutable

Inherits:
Executable show all
Defined in:
lib/rubish/batch_executable.rb

Overview

wraps all the processing in a context with a job (which encapsulates a thread).

Instance Attribute Summary

Attributes inherited from Executable

#working_directory

Instance Method Summary collapse

Methods inherited from Executable

#awk, #cd, #each, #each!, #err, #err=, #first, #head, #i, #i=, #io, #last, #map, #map!, #o, #o=, #sed, #tail

Constructor Details

#initialize(context, &block) ⇒ BatchExecutable

Returns a new instance of BatchExecutable.



6
7
8
9
# File 'lib/rubish/batch_executable.rb', line 6

def initialize(context,&block)
  @context = context
  @proc = block
end

Instance Method Details

#execObject



23
24
25
# File 'lib/rubish/batch_executable.rb', line 23

def exec
  exec!.wait
end

#exec!Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubish/batch_executable.rb', line 11

def exec!
  ctxt = @context.derive(nil,self.i,self.o,self.err)
  # this block will execute in a thread
  Rubish::Job::ThreadJob.new {
    begin
      ctxt.eval &@proc
    ensure
      ctxt.job_control.waitall
    end
  }
end