Sha256: 8433cdbb7ebb3f636e5300db0088753dcaea60dc0d25657cc336975849b59a77

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module BloodContracts
  module Instrumentation
    module SessionFinalizer
      # Multi-threaded implementation of Session finalizer
      module Threads
        # Run the instruments against the session in a Thread in a loop
        # Pros:
        #   - parallel execution of instruments (up to GIL)
        #   - one failed instrument do not affect the others
        # Cons:
        #   - creating a thread has costs
        #   - do not parallel with the BC::Refined matching, as we need to
        #     finish the threads, join them to main Thread
        #
        # @param instruments [Array<Instrument>] list of Instruments to run
        #   against the session
        # @param session [Session] object that hold information about matching
        #   process, argument for Instrument#call
        #
        # @return [Nothing]
        #
        def self.finalize!(instruments, session)
          threads = instruments.map do |i|
            Thread.new { i.call(session) }
          end
          threads.map(&:join)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blood_contracts-instrumentation-0.1.1 lib/blood_contracts/instrumentation/session_finalizer/threads.rb
blood_contracts-instrumentation-0.1.0 lib/blood_contracts/instrumentation/session_finalizer/threads.rb