Class: Turbopuffer::Internal::RespondAsync::Timeout Private

Inherits:
Object
  • Object
show all
Defined in:
lib/turbopuffer/internal/respond_async.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Timeout tracking for async polling.

Instance Method Summary collapse

Constructor Details

#initialize(timeout) ⇒ Timeout

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Timeout.

Parameters:

  • timeout (Float)


28
29
30
# File 'lib/turbopuffer/internal/respond_async.rb', line 28

def initialize(timeout)
  @deadline = Turbopuffer::Internal::Util.monotonic_secs + timeout
end

Instance Method Details

#poll_timeoutFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Float)


38
39
40
# File 'lib/turbopuffer/internal/respond_async.rb', line 38

def poll_timeout
  [remaining, POLL_REQUEST_TIMEOUT].min
end

#remainingFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Float)


33
34
35
# File 'lib/turbopuffer/internal/respond_async.rb', line 33

def remaining
  [@deadline - Turbopuffer::Internal::Util.monotonic_secs, 0].max
end

#sleep_durationFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Float)


43
44
45
# File 'lib/turbopuffer/internal/respond_async.rb', line 43

def sleep_duration
  [remaining, POLL_INTERVAL].min
end