public
Description: A process execution library which doesn't suck.
Clone URL: git://github.com/codahale/ropen.git
Search Repo:
Stop running events in separate threads. If you need long-running events, 
write them yourself.
codahale (author)
Thu May 15 14:18:59 -0700 2008
commit  b18d73130f5f0562b5085cab15fd17c262964868
tree    703da2a5f68dfd289b654b46847ff761750072e4
parent  da88232070673ae91d2ea7dbc9f9de34891d2eea
...
8
9
10
11
12
13
14
...
20
21
22
23
 
24
25
26
...
28
29
30
31
32
33
34
...
8
9
10
 
11
12
13
...
19
20
21
 
22
23
24
25
...
27
28
29
 
30
31
32
0
@@ -8,7 +8,6 @@
0
   
0
   def initialize
0
     @callbacks = []
0
- @running_callbacks = []
0
   end
0
   
0
   def on_output(&block)
0
@@ -20,7 +19,7 @@
0
       until stream.eof?
0
         data = stream.readpartial(1024)
0
         @callbacks.each do |e|
0
- @running_callbacks << Thread.new(data, &e)
0
+ e.call(data)
0
         end
0
       end
0
     end
0
@@ -28,7 +27,6 @@
0
   
0
   def finish
0
     @thread.join
0
- @running_callbacks.each { |t| t.join }
0
   end
0
   
0
 end
...
27
28
29
30
 
 
 
31
32
33
34
35
36
 
37
38
39
40
41
 
42
43
44
45
46
47
48
49
50
 
 
51
52
53
...
27
28
29
 
30
31
32
33
34
35
36
 
 
37
38
39
40
 
 
41
42
43
 
44
45
 
 
 
 
46
47
48
49
50
0
@@ -27,27 +27,24 @@
0
     @events.callbacks.should == [callback]
0
   end
0
   
0
- it "should run collected events in parallel" do
0
+ it "should run collected events on a given stream" do
0
+ output = []
0
+
0
     @stream.should_receive(:eof?).and_return(false, false, true)
0
     @stream.should_receive(:readpartial).with(an_instance_of(Numeric)).and_return("blah", "blee")
0
     
0
     @events.on_output do |line|
0
- ThreadSafeStorage.instance.stuff << [1, line]
0
- sleep 1
0
+ output << [1, line]
0
     end
0
     
0
     @events.on_output do |line|
0
- ThreadSafeStorage.instance.stuff << [2, line]
0
- sleep 2
0
+ output << [2, line]
0
     end
0
     
0
- start_time = Time.now
0
     @events.run(@stream)
0
     @events.finish
0
- elapsed_time = Time.now - start_time
0
- elapsed_time.should < 2.1
0
- elapsed_time.should > 1.9
0
- ThreadSafeStorage.instance.stuff.transpose.last.should == ["blah", "blah", "blee", "blee"]
0
+
0
+ output.transpose.last.should == ["blah", "blah", "blee", "blee"]
0
   end
0
   
0
 end

Comments

    No one has commented yet.