Class: Supabase::Auth::Timer
- Inherits:
-
Object
- Object
- Supabase::Auth::Timer
- Defined in:
- lib/supabase/auth/timer.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #cancel ⇒ Object
-
#initialize(interval, &block) ⇒ Timer
constructor
A new instance of Timer.
- #start ⇒ Object
Constructor Details
#initialize(interval, &block) ⇒ Timer
Returns a new instance of Timer.
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
35 36 37 |
# File 'lib/supabase/auth/timer.rb', line 35 def alive? @thread&.alive? || false end |
#cancel ⇒ Object
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 |
#start ⇒ Object
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 |