Module: Julewire::Core::LocalStorage

Defined in:
lib/julewire/core/local_storage.rb

Overview

Process/ractor-local storage for facade lookups. The ractor bridge can set the current runtime from inside a child ractor, but the getter side still runs inside core through Julewire.* facade calls.

Class Method Summary collapse

Class Method Details

.after_fork!Object



45
46
47
48
49
50
# File 'lib/julewire/core/local_storage.rb', line 45

def after_fork!
  runtime = runtime_ref.get
  @runtime_mutex = Mutex.new
  @runtime_ref = Concurrent::AtomicReference.new(runtime)
  nil
end

.context_storeObject



37
38
39
# File 'lib/julewire/core/local_storage.rb', line 37

def context_store
  context_store_value || store_context(ContextStore.new)
end

.main_ractor?Boolean

Private testing seam for storage-selection behavior.

Returns:

  • (Boolean)


53
54
55
# File 'lib/julewire/core/local_storage.rb', line 53

def main_ractor?
  ::Ractor.main?
end

.reset_context_store!Object



41
42
43
# File 'lib/julewire/core/local_storage.rb', line 41

def reset_context_store!
  store_context(nil)
end

.runtimeObject



21
22
23
24
25
26
27
# File 'lib/julewire/core/local_storage.rb', line 21

def runtime
  return ractor_runtime if ractor_local_storage?

  runtime_ref.get || runtime_mutex.synchronize do
    runtime_ref.get || Runtime.new.tap { runtime_ref.set(it) }
  end
end

.runtime=(runtime) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/julewire/core/local_storage.rb', line 29

def runtime=(runtime)
  if ractor_local_storage?
    ::Ractor[RUNTIME_KEY] = runtime
  else
    runtime_ref.set(runtime)
  end
end