Class: Jefe::EM

Inherits:
Object
  • Object
show all
Defined in:
lib/jefe.rb

Defined Under Namespace

Classes: ProcessHandler

Instance Method Summary collapse

Constructor Details

#initialize(printer) ⇒ EM

Returns a new instance of EM.



64
65
66
67
# File 'lib/jefe.rb', line 64

def initialize(printer)
  @printer = printer
  @connections = []
end

Instance Method Details

#add(name, command) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/jefe.rb', line 75

def add name, command
  PTY.spawn(command) do |output, input, pid|
    input.close
    
    EM.attach output, ProcessHandler do |c|
      c.init name, pid, @printer
      bind(c)
    end
  end
end

#bind(c) ⇒ Object



91
92
93
94
# File 'lib/jefe.rb', line 91

def bind c
  @connections.push c
  c.engine = self
end

#startObject



69
70
71
72
73
# File 'lib/jefe.rb', line 69

def start
  EM.run do
    yield self
  end
end

#stopObject



86
87
88
89
# File 'lib/jefe.rb', line 86

def stop
  @connections.each &:stop
  EM.stop
end

#unbind(c) ⇒ Object



96
97
98
99
# File 'lib/jefe.rb', line 96

def unbind c
  @connections.delete c
  stop if @connections.empty?
end