concurrent-sequential 0.1 → 0.2

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.
@@ -35,7 +35,7 @@ class MockSequencer
35
35
  @queue = []
36
36
  end
37
37
 
38
- def soon(&block)
38
+ def later(&block)
39
39
  raise ArgumentError, "No block given" unless block
40
40
  @queue << block
41
41
  self
@@ -39,27 +39,33 @@ module Sequential
39
39
  class ThreadSequencer
40
40
  def initialize
41
41
  @queue = Queue.new
42
- @running = true
42
+ @shutdown = false
43
43
  @thread = Thread.new { run }
44
44
  end
45
45
 
46
- def soon(&block)
46
+ def later(&block)
47
47
  raise ArgumentError, "No block given" unless block
48
48
  @queue << block
49
49
  self
50
50
  end
51
51
 
52
52
  def shutdown(timeout=nil)
53
- soon { @running = false } if @thread.alive?
53
+ later { @shutdown = true } if @thread.alive?
54
54
  @thread.join(timeout)
55
55
  self
56
56
  end
57
57
 
58
58
  def run
59
- while @running
59
+ until @shutdown and @queue.empty?
60
60
  begin
61
61
  @queue.shift.call
62
- rescue Exception
62
+ rescue Exception => e
63
+ if $DEBUG
64
+ $stderr.puts "Exception in sequencer loop:"
65
+ $stderr.puts "${e.class}: #{e}"
66
+ $stderr.puts e.backtrace
67
+ $stderr.puts "---"
68
+ end
63
69
  end
64
70
  end
65
71
  self
@@ -7,21 +7,21 @@ describe mock_sequencer do
7
7
  @sequencer = mock_sequencer.new
8
8
  end
9
9
 
10
- it "should accept blocks via #{mock_sequencer}#soon" do
11
- @sequencer.soon { }
10
+ it "should accept blocks via #{mock_sequencer}#later" do
11
+ @sequencer.later { }
12
12
  end
13
13
 
14
14
  it "should execute submitted blocks after submission" do
15
15
  calls = mock("calls")
16
- @sequencer.soon { calls.a }
16
+ @sequencer.later { calls.a }
17
17
  calls.should_receive(:a)
18
18
  @sequencer.run
19
19
  end
20
20
 
21
21
  it "should execute reentrant blocks completely and in submission order" do
22
22
  calls = mock("calls")
23
- @sequencer.soon do
24
- @sequencer.soon { calls.b }
23
+ @sequencer.later do
24
+ @sequencer.later { calls.b }
25
25
  calls.a
26
26
  end
27
27
  calls.should_receive(:a).ordered
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: concurrent-sequential
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2008-06-03 00:00:00 -04:00
6
+ version: "0.2"
7
+ date: 2008-06-07 00:00:00 -04:00
8
8
  summary: Sequenced asynchronous actions
9
9
  require_paths:
10
10
  - lib