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

Enable Fiber.current and Fiber#alive? call inside ractor

This commit is contained in:
Delton Ding 2020-12-22 15:30:59 +09:00 committed by Koichi Sasada
parent 487355873a
commit c6d7e02b90
Notes: git 2020-12-23 03:27:41 +09:00
2 changed files with 25 additions and 0 deletions

3
cont.c
View file

@ -2744,6 +2744,9 @@ ruby_Init_Continuation_body(void)
void
ruby_Init_Fiber_as_Coroutine(void)
{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
rb_define_method(rb_cFiber, "transfer", rb_fiber_m_transfer, -1);
rb_define_method(rb_cFiber, "alive?", rb_fiber_alive_p, 0);
rb_define_singleton_method(rb_cFiber, "current", rb_fiber_s_current, 0);

22
test/fiber/test_ractor.rb Normal file
View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
require "test/unit"
require "fiber"
class TestFiberCurrentRactor < Test::Unit::TestCase
def setup
skip unless defined? Ractor
end
def test_ractor_shareable
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
require "fiber"
r = Ractor.new do
Fiber.new do
Fiber.current.class
end.resume
end
assert_equal(Fiber, r.take)
end;
end
end