Module: Datadog::Core::Utils::AtForkMonkeyPatch::KernelMonkeyPatch

Defined in:
lib/datadog/core/utils/at_fork_monkey_patch.rb

Overview

Adds ‘at_fork` behavior; see parent module for details.

Instance Method Summary collapse

Instance Method Details

#forkObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/datadog/core/utils/at_fork_monkey_patch.rb', line 51

def fork
  # If a block is provided, it must be wrapped to trigger callbacks.
  child_block = if block_given?
                  proc do
                    AtForkMonkeyPatch.run_at_fork_blocks(:child)

                    # Invoke original block
                    yield
                  end
                end

  # Start fork
  # If a block is provided, use the wrapped version.
  result = child_block.nil? ? super : super(&child_block)

  # When fork gets called without a block, it returns twice:
  # If we're in the fork, result = nil: trigger child callbacks.
  # If we're in the parent, result = pid: we do nothing.
  # (If it gets called with a block, it only returns on the parent)
  AtForkMonkeyPatch.run_at_fork_blocks(:child) if result.nil?

  result
end