Sha256: 11e5772f077f42786c9ffcc3c5dcc3ca578f0017544bdbbaed08cdfdfdc59a5b

Contents?: true

Size: 848 Bytes

Versions: 4

Compression:

Stored size: 848 Bytes

Contents

# coding: utf-8
require 'timeout'

module Hallon
  # Extends Hallon objects with a method that allows synchronous loading of objects.
  module Loadable
    # Wait until the object has loaded.
    #
    # @example waiting for a track to load
    #   track = Hallon::Track.new(track_uri).load
    #
    # @param [Numeric] timeout after this time, if the object is not loaded, an error is raised.
    # @return [self]
    # @raise [Hallon::TimeoutError] after `timeout` seconds if the object does not load.
    def load(timeout = Hallon.load_timeout)
      Timeout.timeout(timeout, Hallon::TimeoutError) do
        until loaded?
          session.process_events

          if respond_to?(:status)
            Error.maybe_raise(status, :ignore => :is_loading)
          end

          sleep(0.001)
        end

        self
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hallon-0.18.2 lib/hallon/loadable.rb
hallon-0.18.1 lib/hallon/loadable.rb
hallon-0.18.0 lib/hallon/loadable.rb
hallon-0.17.0 lib/hallon/loadable.rb