Module: Raptor::ThreadLocals

Defined in:
lib/raptor/thread_locals.rb,
sig/generated/raptor/thread_locals.rbs

Overview

Owns Raptor's reusable per-thread values and clears application thread locals after each request.

Constant Summary collapse

PRESERVED_KEYS =

Returns:

  • (Object)
[
  :raptor_http_parser,
  :raptor_read_buffer,
  :raptor_response_buffer,
].freeze

Class Method Summary collapse

Class Method Details

.clearvoid

This method returns an undefined value.

Clears application-owned true thread locals while retaining Raptor's reusable per-thread values.

RBS:

  • () -> void



31
32
33
34
35
36
# File 'lib/raptor/thread_locals.rb', line 31

def self.clear
  thread = Thread.current
  thread.thread_variables.each do |key|
    thread.thread_variable_set(key, nil) unless PRESERVED_KEYS.include?(key)
  end
end

.fetch(key) { ... } ⇒ Object

Returns a reusable value stored on the current thread.

RBS:

  • (Symbol key) { () -> untyped } -> untyped

Parameters:

  • key (Symbol)

Yields:

Yield Returns:

  • (Object)

Returns:

  • (Object)


20
21
22
23
# File 'lib/raptor/thread_locals.rb', line 20

def self.fetch(key)
  thread = Thread.current
  thread.thread_variable_get(key) || thread.thread_variable_set(key, yield)
end