Class: Nanoc::Int::Compiler::Phases::Resume

Inherits:
Abstract
  • Object
show all
Defined in:
lib/nanoc/base/services/compiler/phases/resume.rb

Overview

Provides functionality for suspending and resuming item rep compilation (using fibers).

Instance Method Summary collapse

Methods inherited from Abstract

#call

Constructor Details

#initialize(wrapped:) ⇒ Resume

Returns a new instance of Resume



8
9
10
# File 'lib/nanoc/base/services/compiler/phases/resume.rb', line 8

def initialize(wrapped:)
  super(wrapped: wrapped)
end

Instance Method Details

#run(rep, is_outdated:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nanoc/base/services/compiler/phases/resume.rb', line 13

def run(rep, is_outdated:)
  fiber = fiber_for(rep, is_outdated: is_outdated) { yield }
  while fiber.alive?
    Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
    res = fiber.resume

    case res
    when Nanoc::Int::Errors::UnmetDependency
      Nanoc::Int::NotificationCenter.post(:compilation_suspended, rep, res)
      raise(res)
    when Proc
      fiber.resume(res.call)
    else
      # TODO: raise
    end
  end

  Nanoc::Int::NotificationCenter.post(:compilation_ended, rep)
end