Class: Supabase::Auth::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/supabase/auth/timer.rb

Instance Method Summary collapse

Constructor Details

#initialize(interval, &block) ⇒ Timer

Returns a new instance of Timer.

Parameters:

  • interval (Float)

    delay in seconds before firing the callback

  • block (Proc)

    the callback to execute after the delay



8
9
10
11
12
# File 'lib/supabase/auth/timer.rb', line 8

def initialize(interval, &block)
  @interval = interval
  @block = block
  @thread = nil
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/supabase/auth/timer.rb', line 35

def alive?
  @thread&.alive? || false
end

#cancelObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/supabase/auth/timer.rb', line 24

def cancel
  if @thread
    # Don't kill the current thread (e.g. when the callback triggers
    # a new timer via _save_session → _start_auto_refresh_token).
    # Python's threading.Timer.cancel() only prevents future execution;
    # it never terminates an already-running callback.
    @thread.kill unless @thread == Thread.current
    @thread = nil
  end
end

#startObject



14
15
16
17
18
19
20
21
22
# File 'lib/supabase/auth/timer.rb', line 14

def start
  @thread = Thread.new do
    sleep @interval
    @block.call
  rescue StandardError
    # Swallow errors in timer thread (matches Python daemon thread behavior)
  end
  @thread
end