class Nanoc::Core::CompilationPhases::Write

Constants

WORKER_POOL_SIZE

Public Class Methods

new(compiled_content_store:, wrapped:) click to toggle source
# File lib/nanoc/core/compilation_phases/write.rb, line 11
def initialize(compiled_content_store:, wrapped:)
  super(wrapped: wrapped)

  @compiled_content_store = compiled_content_store

  @pool = Concurrent::FixedThreadPool.new(WORKER_POOL_SIZE)

  @writer = Nanoc::Core::ItemRepWriter.new
end

Public Instance Methods

run(rep, is_outdated:) { || ... } click to toggle source
# File lib/nanoc/core/compilation_phases/write.rb, line 29
def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
  yield

  # Caution: Notification must be posted before enqueueing the rep,
  # or we risk a race condition where the :rep_write_ended
  # notification happens before the :rep_write_enqueued one.
  Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)

  @pool.post do
    @writer.write_all(rep, @compiled_content_store)
  end
end
stop() click to toggle source
# File lib/nanoc/core/compilation_phases/write.rb, line 21
def stop
  @pool.shutdown
  @pool.wait_for_termination

  super
end