I'm looking for code review of part of my replacement of timeout() project. Namely, feedback on SleeperNotifier class:https://github.com/ledestin/frugal_timeout/blob/master/lib/frugal_timeout.rb#L125If you would like to give feedback on the whole project, by all means do.  # {{{1 SleeperNotifier  # Executes callback when a request expires.  # 1. Set callback to execute with #onExpiry=.  # 2. Set expiry time with #expireAt.  # 3. After the expiry time comes, execute the callback.  #  # It's possible to set a new expiry time before the time set previously  # expires. In this case, processing of the old request stops and the new  # request processing starts.  class SleeperNotifier # :nodoc:    include MonitorMixin    def initialize      super()      @condVar, @expireAt, @onExpiry = new_cond, nil, proc {}      @thread = Thread.new {        loop {          @onExpiry.call if synchronize {            # Sleep forever until a request comes in.            wait unless @expireAt            timeLeft = calcTimeLeft            disposeOfRequest            elapsedTime = MonotonicTime.measure { wait timeLeft }            elapsedTime >= timeLeft          }        }      }      ObjectSpace.define_finalizer self, proc { @thread.kill }    end    def onExpiry &b      @onExpiry = b    end    def expireAt time      synchronize {        @expireAt = time        signalThread      }    end    private    def calcTimeLeft      synchronize {        delay = @expireAt - MonotonicTime.now        delay < 0 ? 0 : delay      }    end    def disposeOfRequest      @expireAt = nil    end    def signalThread      @condVar.signal    end    def wait sec=nil      @condVar.wait sec    end  end
Sleep and background wakeup system
ruby;multithreading