asynchro 0.1.4 → 0.1.5

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.
data/README.rdoc CHANGED
@@ -29,28 +29,28 @@ then use the `async_state` method:
29
29
  include Asynchro::Extensions
30
30
  ran = [ ]
31
31
 
32
- async_state do
33
- start do
32
+ async_state do |state|
33
+ state.start do
34
34
  ran << :start
35
- state1!
35
+ state.state1!
36
36
  end
37
37
 
38
- state1 do
38
+ state.state1 do
39
39
  ran << :state1
40
- state2!
40
+ state.state2!
41
41
  end
42
42
 
43
- state2 do
43
+ state.state2 do
44
44
  ran << :state2
45
- state3!
45
+ state.state3!
46
46
  end
47
47
 
48
- state3 do
48
+ state.state3 do
49
49
  ran << :state3
50
- finish!
50
+ state.finish!
51
51
  end
52
52
 
53
- finish do
53
+ state.finish do
54
54
  ran << :finish
55
55
  end
56
56
  end
@@ -83,18 +83,18 @@ confirm that they have all completed before moving on. An example is:
83
83
  include Asynchro::Extensions
84
84
  success = false
85
85
 
86
- async_tracker do
87
- perform do |done|
86
+ async_tracker do |tracker|
87
+ tracker.perform do |done|
88
88
  done.call
89
89
  end
90
90
 
91
- perform(4) do |done|
91
+ tracker.perform(4) do |done|
92
92
  4.times do
93
93
  done.call
94
94
  end
95
95
  end
96
96
 
97
- finish do
97
+ tracker.finish do
98
98
  success = true
99
99
  end
100
100
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/asynchro.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "asynchro"
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott Tadman"]
12
- s.date = "2011-09-26"
12
+ s.date = "2011-09-27"
13
13
  s.description = "Provides a number of tools to help make developing and testing asynchronous applications more manageable."
14
14
  s.email = "github@tadman.ca"
15
15
  s.extra_rdoc_files = [
@@ -1,6 +1,6 @@
1
1
  module Asynchro::Extensions
2
2
  def async_tracker(&block)
3
- Asynchro::Tracker.new(self, &block)
3
+ Asynchro::Tracker.new(&block)
4
4
  end
5
5
 
6
6
  def async_state(&block)
@@ -1,12 +1,12 @@
1
1
  class Asynchro::Tracker
2
2
  # Creates a new tracker. If a block is given, this block is called with
3
3
  # the new instance as an argument, and the tracker is automatically run.
4
- def initialize(context = self)
4
+ def initialize
5
5
  @sequence = 0
6
- @context = context
7
6
 
8
7
  if (block_given?)
9
- instance_eval(&Proc.new)
8
+ yield(self)
9
+
10
10
  self.run!
11
11
  end
12
12
  end
@@ -15,7 +15,11 @@ class Asynchro::Tracker
15
15
  # called if this object is initialized without a supplied block as in that
16
16
  # case, this would have been called already.
17
17
  def run!
18
- @procs and @procs.each { |proc| @context.instance_eval { proc.call } }
18
+ if (@procs)
19
+ @procs.each(&:call)
20
+ else
21
+ @finish and @finish.each(&:call)
22
+ end
19
23
  end
20
24
 
21
25
  # Executes this block when all the actions to be performed have checked in
@@ -25,6 +29,12 @@ class Asynchro::Tracker
25
29
  @finish << block
26
30
  end
27
31
 
32
+ # Returns true if this tracker has completed all supplied blocks, or false
33
+ # otherwise.
34
+ def finished?
35
+ !@blocks or @blocks.empty?
36
+ end
37
+
28
38
  # Performs an action. The supplied block will be called with a callback
29
39
  # tracking Proc that should be triggered with `call` as many times as
30
40
  # are specified in the `count` argument. When the correct number of calls
@@ -41,8 +51,8 @@ class Asynchro::Tracker
41
51
  @blocks.delete(_sequence)
42
52
  end
43
53
 
44
- if (@blocks.empty?)
45
- @finish and @finish.each { |proc| @context.instance_eval { proc.call } }
54
+ if (self.finished?)
55
+ @finish and @finish.each(&:call)
46
56
  end
47
57
  end
48
58
  }
@@ -3,23 +3,25 @@ require 'helper'
3
3
  class TestAsynchroExtensions < Test::Unit::TestCase
4
4
  include Asynchro::Extensions
5
5
 
6
- def test_async_tracker_implicit
7
- tracker = nil
6
+ def test_async_tracker
7
+ @context = nil
8
8
  finished = false
9
9
 
10
- async_tracker do
11
- perform do |callback|
12
- tracker = self
10
+ async_tracker do |tracker|
11
+ tracker.perform do |callback|
12
+ @context = self
13
13
  callback.call
14
14
  end
15
15
 
16
- finish do
16
+ tracker.finish do
17
17
  finished = true
18
18
  end
19
19
  end
20
20
 
21
- assert_equal Asynchro::Tracker, tracker.class
22
- assert_equal true, finished
21
+ assert_eventually(1) do
22
+ assert_equal TestAsynchroExtensions, @context.class
23
+ assert_equal true, finished
24
+ end
23
25
  end
24
26
 
25
27
  def test_async_state_explicit
@@ -1,12 +1,25 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestAsynchroTracker < Test::Unit::TestCase
4
- def test_async_chain_explicit
4
+ def test_defaults
5
+ finished = false
6
+
7
+ tracker = Asynchro::Tracker.new do |tracker|
8
+ tracker.finish do
9
+ finished = true
10
+ end
11
+ end
12
+
13
+ assert_equal true, finished
14
+ assert_equal true, tracker.finished?
15
+ end
16
+
17
+ def test_simple_tracker
5
18
  count = 0
6
19
 
7
- Asynchro::Tracker.new do |chain|
8
- chain.perform do |done|
9
- chain.perform do |done|
20
+ Asynchro::Tracker.new do |tracker|
21
+ tracker.perform do |done|
22
+ tracker.perform do |done|
10
23
  count += 2
11
24
  done.call
12
25
  end
@@ -15,14 +28,14 @@ class TestAsynchroTracker < Test::Unit::TestCase
15
28
  done.call
16
29
  end
17
30
 
18
- chain.perform(4) do |done|
31
+ tracker.perform(4) do |done|
19
32
  4.times do
20
33
  count += 1
21
34
  done.call
22
35
  end
23
36
  end
24
37
 
25
- chain.finish do
38
+ tracker.finish do
26
39
  success = true
27
40
  end
28
41
  end
@@ -31,22 +44,4 @@ class TestAsynchroTracker < Test::Unit::TestCase
31
44
  count == 7
32
45
  end
33
46
  end
34
-
35
- def test_async_chain_implicit
36
- success = false
37
-
38
- Asynchro::Tracker.new do
39
- perform do |done|
40
- done.call
41
- end
42
-
43
- finish do
44
- success = true
45
- end
46
- end
47
-
48
- assert_eventually(5) do
49
- success
50
- end
51
- end
52
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-26 00:00:00.000000000Z
12
+ date: 2011-09-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &2155053420 !ruby/object:Gem::Requirement
16
+ requirement: &2154668920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155053420
24
+ version_requirements: *2154668920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2155052560 !ruby/object:Gem::Requirement
27
+ requirement: &2154668040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2155052560
35
+ version_requirements: *2154668040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &2155051700 !ruby/object:Gem::Requirement
38
+ requirement: &2154657980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2155051700
46
+ version_requirements: *2154657980
47
47
  description: Provides a number of tools to help make developing and testing asynchronous
48
48
  applications more manageable.
49
49
  email: github@tadman.ca