Sha256: cc40cdb5920af34ca43ebe3e367168eb1c5ec7dd4a09f0f5650953e465e766a0

Contents?: true

Size: 763 Bytes

Versions: 25

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

module ActiveSupport
  module ForkTracker # :nodoc:
    module CoreExt
      def _fork
        pid = super
        if pid == 0
          ForkTracker.after_fork_callback
        end
        pid
      end
    end

    @pid = Process.pid
    @callbacks = []

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

      def hook!
        ::Process.singleton_class.prepend(CoreExt)
      end

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

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

ActiveSupport::ForkTracker.hook!

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
activesupport-8.0.2 lib/active_support/fork_tracker.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/activesupport-8.0.1/lib/active_support/fork_tracker.rb
activesupport-8.0.1 lib/active_support/fork_tracker.rb
activesupport-8.0.0.1 lib/active_support/fork_tracker.rb
activesupport-7.2.2.1 lib/active_support/fork_tracker.rb
activesupport-8.0.0 lib/active_support/fork_tracker.rb
activesupport-7.2.2 lib/active_support/fork_tracker.rb
activesupport-8.0.0.rc2 lib/active_support/fork_tracker.rb
activesupport-7.2.1.2 lib/active_support/fork_tracker.rb
activesupport-8.0.0.rc1 lib/active_support/fork_tracker.rb
activesupport-7.2.1.1 lib/active_support/fork_tracker.rb
activesupport-8.0.0.beta1 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/fork_tracker.rb
omg-activesupport-8.0.0.alpha1 lib/active_support/fork_tracker.rb
activesupport-7.2.1 lib/active_support/fork_tracker.rb