1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* cont.c (Fiber#pass): rename to Fiber#yield. Block parameter

of fiber body receive first yield values.
  e.g.: Fiber.new{|x| p x}.yield(:ok) #=> :ok
* cont.c: rename rb_context_t#retval to rb_context_t#value.
* test/ruby/test_fiber.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-06-02 07:48:29 +00:00
parent 66d4a354a8
commit 6b3ef2249c
3 changed files with 68 additions and 47 deletions

View file

@ -4,25 +4,27 @@ class TestFiber < Test::Unit::TestCase
def test_normal
f = Fiber.current
assert_equal(:ok2,
Fiber.new(:ok1){|e|
Fiber.new{|e|
assert_equal(:ok1, e)
assert_equal(f, Fiber.prev)
Fiber.pass :ok2
}.pass)
Fiber.yield :ok2
}.yield(:ok1)
)
assert_equal([:a, :b], Fiber.new{|a, b| [a, b]}.yield(:a, :b))
end
def test_term
assert_equal(:ok, Fiber.new{:ok}.pass)
assert_equal(:ok, Fiber.new{:ok}.yield)
assert_equal([:a, :b, :c, :d, :e],
Fiber.new{
Fiber.new{
Fiber.new{
Fiber.new{
[:a]
}.pass + [:b]
}.pass + [:c]
}.pass + [:d]
}.pass + [:e])
}.yield + [:b]
}.yield + [:c]
}.yield + [:d]
}.yield + [:e])
end
def test_many_fibers
@ -33,7 +35,7 @@ class TestFiber < Test::Unit::TestCase
assert_equal(max,
max.times{|i|
Fiber.new{
}.pass
}.yield
}
)
end
@ -42,9 +44,14 @@ class TestFiber < Test::Unit::TestCase
assert_raise(ArgumentError){
Fiber.new # Fiber without block
}
assert_raise(RuntimeError){
assert_raise(FiberError){
f = Fiber.new{}
Thread.new{f.pass}.join # Fiber passing across thread
Thread.new{f.yield}.join # Fiber yielding across thread
}
assert_raise(FiberError){
f = Fiber.new{}
f.yield
f.yield
}
end
@ -52,14 +59,14 @@ class TestFiber < Test::Unit::TestCase
ary = []
f2 = nil
f1 = Fiber.new{
ary << f2.pass(:foo)
ary << f2.yield(:foo)
:bar
}
f2 = Fiber.new{
ary << f1.pass(:baz)
ary << f1.yield(:baz)
:ok
}
assert_equal(:ok, f1.pass)
assert_equal(:ok, f1.yield)
assert_equal([:baz, :bar], ary)
end
end