diff options
| author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2024-11-20 19:40:17 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-20 19:40:17 +1300 |
| commit | 9c268302bfb4890d3757caa60981802a88bfbd89 (patch) | |
| tree | 7aab2128ac5caf11baddee06d7b357dc6ab5c43d /test | |
| parent | 86b1c838573b5459e9e5b8fab62ec3430d2ac872 (diff) | |
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]
Notes
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/fiber/scheduler.rb | 10 |
1 files changed, 10 insertions, 0 deletions
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 |
