Module: ActiveSupport::ForkTracker

Defined in:
lib/active_support/fork_tracker.rb

Overview

:nodoc:

Defined Under Namespace

Modules: CoreExt, CoreExtPrivate, ModernCoreExt

Class Method Summary collapse

Class Method Details

.after_fork(&block) ⇒ Object



67
68
69
70
# File 'lib/active_support/fork_tracker.rb', line 67

def after_fork(&block)
  @callbacks << block
  block
end

.after_fork_callbackObject



40
41
42
43
44
45
46
# File 'lib/active_support/fork_tracker.rb', line 40

def after_fork_callback
  new_pid = Process.pid
  if @pid != new_pid
    @callbacks.each(&:call)
    @pid = new_pid
  end
end

.hook!Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/active_support/fork_tracker.rb', line 56

def hook!
  if Process.respond_to?(:_fork) # Ruby 3.1+
    ::Process.singleton_class.prepend(ModernCoreExt)
  elsif Process.respond_to?(:fork)
    ::Object.prepend(CoreExtPrivate) if RUBY_VERSION < "3.0"
    ::Kernel.prepend(CoreExtPrivate)
    ::Kernel.singleton_class.prepend(CoreExt)
    ::Process.singleton_class.prepend(CoreExt)
  end
end

.unregister(callback) ⇒ Object



72
73
74
# File 'lib/active_support/fork_tracker.rb', line 72

def unregister(callback)
  @callbacks.delete(callback)
end