contrails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/contrails/chainable.rb +7 -6
- data/lib/contrails/parallel.rb +1 -1
- data/lib/contrails/process.rb +1 -1
- data/lib/contrails/serial.rb +25 -0
- data/spec/process_spec.rb +9 -5
- metadata +3 -2
data/Rakefile
CHANGED
@@ -38,7 +38,7 @@ spec = Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
# Change these as appropriate
|
40
40
|
s.name = "contrails"
|
41
|
-
s.version = "0.2.
|
41
|
+
s.version = "0.2.2"
|
42
42
|
s.summary = "Declarative concurrency for EventMachine"
|
43
43
|
s.author = "Tim Cowlishaw"
|
44
44
|
s.email = "tim@timcowlishaw.co.uk"
|
data/lib/contrails/chainable.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'em/deferrable'
|
2
|
-
autoload "Parallel", 'contrails/parallel'
|
3
|
-
autoload "Process", 'contrails/process'
|
4
2
|
module Contrails
|
5
3
|
module Chainable
|
6
4
|
|
5
|
+
def run
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
7
9
|
module ClassMethods
|
8
10
|
def return(&b)
|
9
11
|
self.new(&b)
|
@@ -16,18 +18,17 @@ module Contrails
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def bind(other)
|
19
|
-
|
20
|
-
|
21
|
-
return p
|
21
|
+
require 'contrails/serial'
|
22
|
+
Serial.new(self, other)
|
22
23
|
end
|
23
24
|
|
24
25
|
def distribute(other)
|
26
|
+
require 'contrails/parallel'
|
25
27
|
Parallel.new(self, other)
|
26
28
|
end
|
27
29
|
|
28
30
|
def call(*a)
|
29
31
|
result = run(*a)
|
30
|
-
result = result.is_a?(Array) ? result : [result]
|
31
32
|
self.succeed(*result)
|
32
33
|
end
|
33
34
|
|
data/lib/contrails/parallel.rb
CHANGED
data/lib/contrails/process.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'contrails/chainable'
|
2
|
+
module Contrails
|
3
|
+
class Serial
|
4
|
+
include Chainable
|
5
|
+
def initialize(*procs)
|
6
|
+
@procs = procs
|
7
|
+
@procs_with_callbacks = @procs.map(&:dup)
|
8
|
+
@procs_with_callbacks.zip(@procs_with_callbacks[1..-1]).each do |proc1, proc2|
|
9
|
+
if proc2
|
10
|
+
proc1.callback {|*args| proc2.call(*args) }
|
11
|
+
else
|
12
|
+
proc1.callback {|*args| self.succeed(*args)}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def bind(other)
|
18
|
+
Contrails::Serial.new(*(@procs + [other]))
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(*args)
|
22
|
+
@procs_with_callbacks.first.call(*args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/process_spec.rb
CHANGED
@@ -51,9 +51,13 @@ describe Contrails::Process do
|
|
51
51
|
it "passes the return value of each process to its successors" do
|
52
52
|
for_all do
|
53
53
|
int= integer
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
context = mock
|
55
|
+
context.expects(:test).with(int).in_sequence
|
56
|
+
context.expects(:test).with(int+1).in_sequence
|
57
|
+
context.expects(:test).with(int+2).in_sequence
|
58
|
+
proc1 = Contrails::Process.new { |x| context.test(x); x+1}
|
59
|
+
proc2 = Contrails::Process.new { |x| context.test(x); x+1}
|
60
|
+
proc3 = Contrails::Process.new { |x| context.test(x); x+1}
|
57
61
|
async_assertion(proc1.bind(proc2).bind(proc3), int) {|x| x.should == int+3}
|
58
62
|
end
|
59
63
|
end
|
@@ -100,8 +104,8 @@ describe Contrails::Process do
|
|
100
104
|
it "executes any subsequently distributed processes in parallel" do
|
101
105
|
for_all {
|
102
106
|
time = float
|
103
|
-
guard time > 0.
|
104
|
-
guard time < 0.
|
107
|
+
guard time > 0.1
|
108
|
+
guard time < 0.3
|
105
109
|
context = mock
|
106
110
|
context.expects(:first).in_sequence
|
107
111
|
context.expects(:second).in_sequence
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: contrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Cowlishaw
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/contrails/process.rb
|
55
55
|
- lib/contrails/chainable.rb
|
56
56
|
- lib/contrails/parallel.rb
|
57
|
+
- lib/contrails/serial.rb
|
57
58
|
- lib/contrails/utils.rb
|
58
59
|
- lib/contrails/semaphore.rb
|
59
60
|
- lib/contrails/helpers.rb
|
@@ -73,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
74
|
requirements:
|
74
75
|
- - ">="
|
75
76
|
- !ruby/object:Gem::Version
|
76
|
-
hash:
|
77
|
+
hash: -2865547770720461986
|
77
78
|
segments:
|
78
79
|
- 0
|
79
80
|
version: "0"
|