Sha256: 6719723a14341da26f14aa154f5ec6278f743baad024934f012b9ce828ecb93c

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

module Wayfarer
  module Networking
    Context = Struct.new(:strategy) do
      def fetch(url)
        supervise { strategy.fetch(instance, url) }
      end

      def live
        supervise { strategy.live(instance) }
      end

      def renew
        strategy.destroy(instance)
      ensure
        @instance = nil
      end

      def instance
        @instance ||= strategy.create
      end

    private

      def supervise
        yield
      rescue *strategy.renew_on, *Wayfarer.config.network.renew_on => e
        renew
      ensure
        # If renewing raises, re-raise the originally caught exception
        # TODO: Not nice this effectively swallows exceptions
        raise e if e
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wayfarer-0.4.6 lib/wayfarer/networking/context.rb