def receive(cmd_id, receive_timeout = nil)
      receive_timeout ||= timeout
      start = Time.now

      until @messages.key?(cmd_id)
        raise Errno::EWOULDBLOCK if (Time.now - start) >= receive_timeout
        if @receive_mutex.try_lock
          begin
            IO.select([socket], [], [], receive_timeout) || raise(Errno::EWOULDBLOCK)
            data = socket.recv(RECV_SIZE)
            break if data.empty?
            driver.parse(data)
          ensure
            @receive_mutex.unlock
          end
        else
          sleep(0.05)
        end
      end
      @messages.delete(cmd_id)
    end
def receive(cmd_id, receive_timeout = nil)
      receive_timeout ||= timeout
      start = Time.now

      until @messages.key?(cmd_id)
        raise Errno::EWOULDBLOCK if (Time.now - start) >= receive_timeout
        if @receive_mutex.try_lock
          begin
            IO.select([socket], [], [], receive_timeout) || raise(Errno::EWOULDBLOCK)
            data = socket.recv(RECV_SIZE)
            break if data.empty?
            driver.parse(data)
          ensure
            @receive_mutex.unlock
          end
        else
          sleep(0.05)
        end
      end
      @messages.delete(cmd_id)
    end
Block until the next message is available from the Web Socket.
 Raises Errno::EWOULDBLOCK if timeout is reached.