strand 0.1.0 → 0.2.0.rc0
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/.gitignore +3 -0
- data/CHANGELOG +13 -0
- data/Gemfile +3 -15
- data/LICENSE.txt +1 -0
- data/README.rdoc +12 -19
- data/Rakefile +10 -57
- data/lib/strand.rb +151 -126
- data/lib/strand/atc.rb +1 -1
- data/lib/strand/em/condition_variable.rb +57 -0
- data/lib/strand/em/mutex.rb +63 -0
- data/lib/strand/em/queue.rb +84 -0
- data/lib/strand/em/thread.rb +305 -0
- data/lib/strand/monitor.rb +193 -0
- data/lib/strand/version.rb +3 -0
- data/spec/spec_helper.rb +9 -5
- data/spec/strand/alive.rb +62 -0
- data/spec/strand/condition_variable.rb +10 -0
- data/spec/strand/condition_variable/broadcast.rb +61 -0
- data/spec/strand/condition_variable/signal.rb +62 -0
- data/spec/strand/condition_variable/wait.rb +20 -0
- data/spec/strand/current.rb +15 -0
- data/spec/strand/exit.rb +148 -0
- data/spec/strand/join.rb +60 -0
- data/spec/strand/local_storage.rb +98 -0
- data/spec/strand/mutex.rb +244 -0
- data/spec/strand/pass.rb +9 -0
- data/spec/strand/queue.rb +124 -0
- data/spec/strand/raise.rb +142 -0
- data/spec/strand/run.rb +5 -0
- data/spec/strand/shared.rb +14 -0
- data/spec/strand/sleep.rb +51 -0
- data/spec/strand/status.rb +44 -0
- data/spec/strand/stop.rb +58 -0
- data/spec/strand/strand.rb +32 -0
- data/spec/strand/value.rb +39 -0
- data/spec/strand/wakeup.rb +60 -0
- data/spec/strand_spec.rb +51 -0
- data/spec/support/fixtures.rb +305 -0
- data/spec/support/scratch.rb +17 -0
- data/spec/thread_spec.rb +20 -0
- data/strand.gemspec +23 -0
- metadata +72 -58
- data/Gemfile.lock +0 -40
- data/lib/strand/condition_variable.rb +0 -78
- data/spec/condition_variable_spec.rb +0 -82
- data/test/helper.rb +0 -30
- data/test/test_strand.rb +0 -121
data/test/helper.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'bundler'
|
|
3
|
-
begin
|
|
4
|
-
Bundler.setup(:default, :development)
|
|
5
|
-
rescue Bundler::BundlerError => e
|
|
6
|
-
$stderr.puts e.message
|
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
|
8
|
-
exit e.status_code
|
|
9
|
-
end
|
|
10
|
-
require 'test/unit'
|
|
11
|
-
|
|
12
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
13
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
14
|
-
require 'strand'
|
|
15
|
-
|
|
16
|
-
class Test::Unit::TestCase
|
|
17
|
-
|
|
18
|
-
def self.test(name, &block)
|
|
19
|
-
name = "test_#{name}" unless name[0,5] == "test_"
|
|
20
|
-
define_method(name) do
|
|
21
|
-
EM.run do
|
|
22
|
-
Fiber.new do
|
|
23
|
-
instance_eval(&block)
|
|
24
|
-
EM.stop
|
|
25
|
-
end.resume
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|
data/test/test_strand.rb
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
require 'helper'
|
|
2
|
-
|
|
3
|
-
class TestStrand < Test::Unit::TestCase
|
|
4
|
-
|
|
5
|
-
test "em" do
|
|
6
|
-
results = []
|
|
7
|
-
|
|
8
|
-
s1 = Strand.new do
|
|
9
|
-
results << "1a"
|
|
10
|
-
Strand.sleep(0.1)
|
|
11
|
-
results << "1b"
|
|
12
|
-
Strand.sleep(0.1)
|
|
13
|
-
results << "1c"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
s2 = Strand.new do
|
|
17
|
-
results << "2a"
|
|
18
|
-
Strand.sleep(0.1)
|
|
19
|
-
results << "2b"
|
|
20
|
-
Strand.sleep(0.1)
|
|
21
|
-
results << "2c"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
s1.join
|
|
25
|
-
s2.join
|
|
26
|
-
|
|
27
|
-
assert_equal false, s1.alive?
|
|
28
|
-
assert_equal false, s2.alive?
|
|
29
|
-
assert_equal %w[1a 2a 1b 2b 1c 2c], results
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "yield" do
|
|
33
|
-
results = []
|
|
34
|
-
|
|
35
|
-
s1 = Strand.new do
|
|
36
|
-
results << "1a"
|
|
37
|
-
Strand.pass
|
|
38
|
-
results << "1b"
|
|
39
|
-
Strand.pass
|
|
40
|
-
results << "1c"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
s2 = Strand.new do
|
|
44
|
-
results << "2a"
|
|
45
|
-
Strand.pass
|
|
46
|
-
results << "2b"
|
|
47
|
-
Strand.pass
|
|
48
|
-
results << "2c"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
s1.join
|
|
52
|
-
s2.join
|
|
53
|
-
|
|
54
|
-
assert_equal false, s1.alive?
|
|
55
|
-
assert_equal false, s2.alive?
|
|
56
|
-
assert_equal %w[1a 2a 1b 2b 1c 2c], results
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "improper_yield" do
|
|
60
|
-
test_fiber = Fiber.current
|
|
61
|
-
strand = Strand.new do
|
|
62
|
-
fiber = Fiber.current
|
|
63
|
-
EM::Timer.new(0.01) do
|
|
64
|
-
assert_raise(FiberError){ fiber.resume }
|
|
65
|
-
test_fiber.resume
|
|
66
|
-
end
|
|
67
|
-
Strand.pass
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
assert strand.join
|
|
71
|
-
Fiber.yield
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
test "improper_pass" do
|
|
75
|
-
fiber = nil
|
|
76
|
-
strand = Strand.new do
|
|
77
|
-
fiber = Fiber.current
|
|
78
|
-
Strand.pass
|
|
79
|
-
Strand.yield
|
|
80
|
-
end
|
|
81
|
-
fiber.resume
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test "strand_list" do
|
|
85
|
-
Strand.new do
|
|
86
|
-
Strand.new{ Strand.yield }
|
|
87
|
-
assert Strand.list.inspect =~ /#<Strand:0x(.+) run>, #<Strand:0x(.+) yielded>/
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
test "wait" do
|
|
92
|
-
x = nil
|
|
93
|
-
cond = Strand::ConditionVariable.new
|
|
94
|
-
Strand.new{ cond.wait; x = 1; cond.signal }
|
|
95
|
-
assert_nil x
|
|
96
|
-
cond.signal
|
|
97
|
-
cond.wait
|
|
98
|
-
assert_equal 1, x
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
test "wait_timeout" do
|
|
102
|
-
x = nil
|
|
103
|
-
cond = Strand::ConditionVariable.new
|
|
104
|
-
Strand.new{ cond.wait; x = 1; cond.signal }
|
|
105
|
-
assert_nil x
|
|
106
|
-
cond.wait(0.01)
|
|
107
|
-
assert_nil x
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
test "signal" do
|
|
111
|
-
result = []
|
|
112
|
-
cond = Strand::ConditionVariable.new
|
|
113
|
-
strand = Strand.new{ result << 1; cond.wait; result << 2 }
|
|
114
|
-
result << 3
|
|
115
|
-
cond.signal
|
|
116
|
-
result << 4
|
|
117
|
-
strand.join
|
|
118
|
-
assert_equal [1, 3, 4, 2], result
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
end
|