# 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 => 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