firehoseio / firehose

Build realtime Ruby web applications. Created by the fine folks at Poll Everywhere.
http://firehose.io/
MIT License
726 stars 72 forks source link

Revert message buffer behavior to 1.2.x. #65

Closed bradgessler closed 8 years ago

bradgessler commented 8 years ago

@thoughtless I believe this fixes all the behavioral issues you brought to light in https://github.com/firehoseio/firehose/commit/b7e412a17d7262c9d04f5115c5a61f0603309f1f

bradgessler commented 8 years ago

If this looks good I'll cut a 1.3.6 gem and yank 1.3.5.

thoughtless commented 8 years ago

How about something like this?

      def remaining_messages
        messages.last(remaining_message_count)
      end

      private

      def remaining_message_count
        count = @channel_sequence - @consumer_sequence

        if count < 0
          # UNEXPECTED: Somehow the sequence is ahead of the channel.
          #             It is likely a bug in the consumer, but we'll assume
          #             the consumer has all the messages.
          0
        elsif count > @message_list.size
          # Consumer is under water since the last request. Just send the most recent message.
          1
        else
          count
        end
      end
bradgessler commented 8 years ago

Yeah, that's way more clear.

thoughtless commented 8 years ago

I put my suggestion into this PR: https://github.com/firehoseio/firehose/pull/66

thoughtless commented 8 years ago

Closing in favor of https://github.com/firehoseio/firehose/pull/66