em-systemcommand 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,7 +89,7 @@ module EventMachine
89
89
  ##
90
90
  # Returns the status object of the popen4 call.
91
91
  def status
92
- Process.waitpid2(pid)[1]
92
+ @status ||= Process.waitpid2(pid)[1]
93
93
  end
94
94
 
95
95
  alias_method :success, :callback
@@ -100,6 +100,9 @@ module EventMachine
100
100
  def unbind name
101
101
  pipes.delete name
102
102
  if pipes.empty?
103
+ exit_callbacks.each do |cb|
104
+ cb.call status
105
+ end
103
106
  if status.exitstatus == 0
104
107
  succeed self
105
108
  else
@@ -118,5 +121,18 @@ module EventMachine
118
121
  @stderr.close
119
122
  val
120
123
  end
124
+
125
+ ##
126
+ # A method to add a callback for when the process unbinds.
127
+ def exit &block
128
+ exit_callbacks << block
129
+ end
130
+
131
+ ##
132
+ # An array of exit callbacks, being called with `status` as
133
+ # parameter when the process is unbound.
134
+ def exit_callbacks
135
+ @exit_callbacks ||= []
136
+ end
121
137
  end
122
138
  end
@@ -1,5 +1,5 @@
1
1
  module Em
2
2
  module Systemcommand
3
- VERSION = "1.1.2"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -2,6 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe EM::SystemCommand do
4
4
 
5
+ it 'should call an exit callback when process is unbound' do
6
+ called = false
7
+ exitstatus = nil
8
+ EM.run do
9
+ EM::SystemCommand.execute 'exit 0;' do |on|
10
+ on.exit do |status|
11
+ called = true
12
+ exitstatus = status.exitstatus
13
+ end
14
+ end
15
+
16
+ EM.assertions do
17
+ called.should == true
18
+ exitstatus.should == 0
19
+ end
20
+ end
21
+ end
22
+
5
23
  it 'should call a success callback when process succeeds' do
6
24
  called = false
7
25
  EM.run do
@@ -110,13 +128,13 @@ describe EM::SystemCommand do
110
128
  it 'should pass multiple command executions' do
111
129
  counter = 0
112
130
  EM.run do
113
- 2.times do
131
+ 10.times do
114
132
  EM::SystemCommand.execute 'ls' do |on|
115
133
  on.success do
116
- 2.times do
134
+ 10.times do
117
135
  EM::SystemCommand.execute 'ls' do |on2|
118
136
  on2.success do
119
- if counter >= 3
137
+ if counter >= 99
120
138
  EM.stop_event_loop
121
139
  else
122
140
  counter += 1
@@ -124,7 +142,7 @@ describe EM::SystemCommand do
124
142
  end
125
143
 
126
144
  on2.failure do
127
- if counter >= 3
145
+ if counter >= 99
128
146
  EM.stop_event_loop
129
147
  else
130
148
  counter += 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-systemcommand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-14 00:00:00.000000000 Z
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -147,7 +147,7 @@ files:
147
147
  - lib/em-systemcommand/version.rb
148
148
  - spec/em-systemcommand/builder_spec.rb
149
149
  - spec/em-systemcommand/pipe_spec.rb
150
- - spec/em-systmcommand_spec.rb
150
+ - spec/em-systemcommand_spec.rb
151
151
  - spec/spec_helper.rb
152
152
  homepage: http://leoc.github.com/em-systemcommand/
153
153
  licenses: []
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: 2192614786888630701
166
+ hash: -3989779150220825362
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  none: false
169
169
  requirements:
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: 2192614786888630701
175
+ hash: -3989779150220825362
176
176
  requirements: []
177
177
  rubyforge_project:
178
178
  rubygems_version: 1.8.24
@@ -182,5 +182,5 @@ summary: Sweeter popen3 for EventMachine.
182
182
  test_files:
183
183
  - spec/em-systemcommand/builder_spec.rb
184
184
  - spec/em-systemcommand/pipe_spec.rb
185
- - spec/em-systmcommand_spec.rb
185
+ - spec/em-systemcommand_spec.rb
186
186
  - spec/spec_helper.rb