From 9c268302bfb4890d3757caa60981802a88bfbd89 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 20 Nov 2024 19:40:17 +1300 Subject: Introduce `Fiber::Scheduler#blocking_operation_wait`. (#12016) Redirect `rb_nogvl` blocking operations to the fiber scheduler if possible to prevent stalling the event loop. [Feature #20876] --- test/fiber/scheduler.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index e6a8256232..ac19bba7a2 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -309,6 +309,16 @@ class Scheduler Addrinfo.getaddrinfo(hostname, nil).map(&:ip_address).uniq end.value end + + def blocking_operation_wait(work) + thread = Thread.new(&work) + + thread.join + + thread = nil + ensure + thread&.kill + end end # This scheduler class implements `io_read` and `io_write` hooks which require -- cgit v1.2.3