Class: Nanoc::Core::CompilationPhases::Write

Inherits:
Abstract
  • Object
show all
Includes:
Nanoc::Core::ContractsSupport
Defined in:
lib/nanoc/core/compilation_phases/write.rb

Constant Summary collapse

WORKER_POOL_SIZE =
5

Instance Method Summary collapse

Methods included from Nanoc::Core::ContractsSupport

enabled?, included, setup_once, warn_about_performance

Methods inherited from Abstract

#call, #start

Constructor Details

#initialize(compiled_content_store:, wrapped:) ⇒ Write

Returns a new instance of Write.



11
12
13
14
15
16
17
18
19
# File 'lib/nanoc/core/compilation_phases/write.rb', line 11

def initialize(compiled_content_store:, wrapped:)
  super(wrapped:)

  @compiled_content_store = compiled_content_store

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

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

Instance Method Details

#run(rep, is_outdated:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



29
30
31
32
33
34
35
36
37
38
39
40
# 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

#stopObject



21
22
23
24
25
26
# File 'lib/nanoc/core/compilation_phases/write.rb', line 21

def stop
  @pool.shutdown
  @pool.wait_for_termination

  super
end