Skip to content

Commit

Permalink
Removed singleton dependency
Browse files Browse the repository at this point in the history
  I have a plan to extract singleton library as bundled gems at Ruby 3.5.
  We should rewrite singleton logic with simple ruby code.
  • Loading branch information
hsbt committed Jan 31, 2024
1 parent 1d156e3 commit f2c7fcc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/webrick/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def random_string(len)
###########

require "timeout"
require "singleton"

##
# Class used to manage timeout handlers across multiple threads.
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down

0 comments on commit f2c7fcc

Please sign in to comment.