Class: Wip::StagingProgress
- Inherits:
-
Object
- Object
- Wip::StagingProgress
- Defined in:
- lib/wip/staging_progress.rb
Overview
Prints a self-overwriting "copying build context files: N/total" line every half second while a slow, silent step is running. Reporting runs on its own thread so a single large file does not make progress appear hung.
Instance Method Summary collapse
-
#finish ⇒ Object
Idempotent: a caller can't know in advance whether tick ever fired.
-
#initialize(out: $stderr, interval: 0.5) ⇒ StagingProgress
constructor
A new instance of StagingProgress.
- #tick(count, total) ⇒ Object
Constructor Details
#initialize(out: $stderr, interval: 0.5) ⇒ StagingProgress
Returns a new instance of StagingProgress.
8 9 10 11 12 13 14 15 |
# File 'lib/wip/staging_progress.rb', line 8 def initialize(out: $stderr, interval: 0.5) @out = out @interval = interval @mutex = Mutex.new @condition = ConditionVariable.new @worker = nil @stopped = false end |
Instance Method Details
#finish ⇒ Object
Idempotent: a caller can't know in advance whether tick ever fired.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wip/staging_progress.rb', line 30 def finish worker = @mutex.synchronize do return unless @worker @stopped = true @condition.broadcast @worker end worker.join @mutex.synchronize do @worker = nil @out.puts @out.flush end end |
#tick(count, total) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wip/staging_progress.rb', line 17 def tick(count, total) @mutex.synchronize do @count = count @total = total print_progress if @worker.nil? || count == total unless @worker @stopped = false @worker = Thread.new { report_on_interval } end end end |