From f2c7fccc9f7261083f36e41dc3fea2fe323afdb2 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 31 Jan 2024 12:45:15 +0900 Subject: [PATCH] Removed singleton dependency I have a plan to extract singleton library as bundled gems at Ruby 3.5. We should rewrite singleton logic with simple ruby code. --- lib/webrick/utils.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index e4902d0b..64a40ae5 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -87,7 +87,6 @@ def random_string(len) ########### require "timeout" - require "singleton" ## # Class used to manage timeout handlers across multiple threads. @@ -116,8 +115,6 @@ def random_string(len) # will print 'foo' # class TimeoutHandler - include Singleton - ## # Mutex used to synchronize access across threads TimeoutMutex = Thread::Mutex.new # :nodoc: @@ -142,6 +139,11 @@ def self.terminate instance.terminate end + def self.instance + @instance ||= new + end + private_class_method :new + ## # Creates a new TimeoutHandler. You should use ::register and ::cancel # instead of creating the timeout handler directly.