wait_pid 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/wait_pid.rb +10 -1
  3. data/spec/spec.wait_pid.rb +18 -9
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
data/lib/wait_pid.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  class WaitPid
3
3
 
4
- def self.wait_pid(pid, test = false)
4
+ def self.wait_nonchild_pid(pid, test = false)
5
5
  # initial test
6
6
  count = 0
7
7
  begin
@@ -20,4 +20,13 @@ class WaitPid
20
20
 
21
21
  end
22
22
 
23
+ def self.wait_nonchild_pids *pids
24
+ require 'thwait'
25
+ all = []
26
+ pids.each{|pid|
27
+ all << Thread.new(pid) {|pid| WaitPid.wait_nonchild_pid pid }
28
+ }
29
+ ThreadsWait.all_waits *all
30
+ end
31
+
23
32
  end
@@ -7,35 +7,44 @@ require_rel '../lib/wait_pid'
7
7
  def spawn command # should return a pid
8
8
  if RUBY_VERSION < '1.9'
9
9
  if OS.linux?
10
- fork { system(command) }
10
+ a = fork { system(command) }
11
11
  else
12
- raise 'todo'
12
+ raise 'todo' # too lazy
13
13
  end
14
14
  else
15
- Process.spawn command
15
+ a = Process.spawn command
16
16
  end
17
+ Thread.new { Process.wait a } # gotta wait for it, or, as child, it never "really" ends in terms of sig 0
18
+ a
17
19
  end
18
20
 
19
21
  describe "wait pid" do
20
22
 
21
23
  it "should warn if a pid doesn't exist" do
22
- out = WaitPid.wait_pid 1234, true
24
+ out = WaitPid.wait_nonchild_pid 1234, true
23
25
  out.should be_a(String)
24
26
  end
25
27
 
26
28
  it "should work without a second argument" do
27
- WaitPid.wait_pid 1234
29
+ WaitPid.wait_nonchild_pid 1234
28
30
  end
29
-
31
+
32
+
30
33
  it "should wait on a pid" do
31
34
  a = spawn 'ruby -e "sleep 1"'
32
- Thread.new { Process.wait a } # gotta wait for it, or, as child, it never "really" ends in terms of sig 0
33
35
  start = Time.now
34
- WaitPid.wait_pid(a)
36
+ WaitPid.wait_nonchild_pid(a)
35
37
  assert(Time.now - start > 0.5)
36
38
  end
37
39
 
38
- it "should be able to wait on more than one pid"
40
+ it "should be able to wait on more than one pid" do
41
+ a = spawn 'ruby -e "sleep 0.5"'
42
+ b = spawn 'ruby -e "sleep 1"'
43
+ start = Time.now
44
+ WaitPid.wait_nonchild_pids a, b
45
+ assert(Time.now - start > 0.75)
46
+ end
47
+
39
48
  it "should be able to optionally output when each of those several dies"
40
49
 
41
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wait_pid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rdp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-18 00:00:00 -07:00
12
+ date: 2009-12-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency