lgierth/promise.rb

View on GitHub
lib/promise/progress.rb

Summary

Maintainability
A
0 mins
Test Coverage
# encoding: utf-8

class Promise
  module Progress
    def on_progress(&block)
      (@on_progress ||= []).tap do |callbacks|
        callbacks << block if block_given?
      end
    end

    def progress(status)
      if pending?
        on_progress.each { |block| block.call(status) }
      end
    end
  end
end