lib/cztop/patterns/lazy_pirate.rb
# Tries sending a message and receiving a valid reply up to the specified
# amount of retries times. The passed block will get any received replies
# and its return value determines whether it was a valid reply or not. If it
# was a valid reply, it's over. Otherwise it'll retrying by sending the
# message again and waiting for replies (if retries left).
#
# @param msg [CZTop::Message, String, ...] the message to send
# @yieldparam reply [CZTop::Message] any reply received
# @yieldreturn [Boolean] whether the reply was valid or not
Tries sending a message and receiving a valid reply up to the specified
amount of retries times. The passed block will get any received replies
and its return value determines whether it was a valid reply or not. If it
was a valid reply, it's over. Otherwise it'll retrying by sending the
message again and waiting for replies (if retries left).
Tries sending a message and receiving a valid reply up to the specified amount of retries times . The passed block will get any received replies and its return value determines whether it was a valid reply or not . If it was a valid reply it ' s over . Otherwise it ' ll retrying by sending the message again and waiting for replies ( if retries left ) .
def send(msg)
    @retries.times do
      @socket << msg
      while true
        if @poller.simple_wait(@timeout)
          reply = @socket.receive
          return if yield(reply) 
        else
          reinit_sock
          break
        end
      end
    end
    raise NoValidReply
  end
def send ( msg ) @retries . times do @socket << msg while true if @poller . simple_wait ( @timeout ) reply = @socket . receive return if yield ( reply ) else reinit_sock break end end end raise NoValidReply end
Tries sending a message and receiving a valid reply up to the specified
amount of retries times.
Tries sending a message and receiving a valid reply up to the specified amount of retries times .
# reply valid or not? # ... reply was invalid, let's read next reply right away # retry by sending message again over fresh socket (possibly to # other endpoint)
whether the reply was valid or not
whether the reply was valid or not
Boolean
msg
the message to send
the message to send
reply
any reply received
any reply received