diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-07-19 10:14:51 +1200 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-09-20 22:07:58 +1200 |
commit | cb8434563d3cc8fc5c3a5aa1e34ad7a9bb542cdb (patch) | |
tree | 8c8aa83cb507d7d1f49199f8c6c554ae00af7a8d /test/fiber/scheduler.rb | |
parent | 4730a1e0ec24cf273d2d93866ef56f9c5ac2a516 (diff) | |
download | ruby-cb8434563d3cc8fc5c3a5aa1e34ad7a9bb542cdb.tar.gz |
Add alternative optional hook for `scheduler_close` to allow public usage of close.
Diffstat (limited to 'test/fiber/scheduler.rb')
-rw-r--r-- | test/fiber/scheduler.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index 740cad02c2..8c2fdcb0e0 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -107,10 +107,22 @@ class Scheduler end end - def close + def scheduler_close + close(true) + end + + def close(internal = false) # $stderr.puts [__method__, Fiber.current].inspect - raise "Scheduler already closed!" if @closed + unless internal + if Fiber.scheduler == self + return Fiber.set_scheduler(nil) + end + end + + if @closed + raise "Scheduler already closed!" + end self.run ensure @@ -119,7 +131,7 @@ class Scheduler @urgent = nil end - @closed = true + @closed ||= true # We freeze to detect any unintended modifications after the scheduler is closed: self.freeze |