<commit_before>class Firehose.Consumer
  constructor: (@config = {}) ->
    # Empty handler for messages.
    @config.message      ||= ->
    # Empty handler for error handling.
    @config.error        ||= ->
    # Empty handler for when we establish a connection.
    @config.connected    ||= ->
    # Empty handler for when we're disconnected.
    @config.disconnected ||= ->
    # The initial connection failed. This is probably triggered when a
    # transport, like WebSockets is supported by the browser, but for whatever
    # reason it can't connect (probably a firewall)
    @config.failed       ||= ->
      throw "Could not connect"
    # Params that we'll tack on to the URL.
    @config.params       ||= {}
    # Do stuff before we send the message into config.message. The sensible
    # default on the webs is to parse JSON.
    @config.parse        ||= JSON.parse
    # Make sure we return ourself out of the constructor so we can chain.
    this

  connect: (delay=0) =>
    @config.connectionVerified = @_upgradeTransport
    if Firehose.WebSocket.supported()
      @upgradeTimeout = setTimeout =>
        ws = new Firehose.WebSocket @config
        ws.connect delay
      , 500
    @transport = new Firehose.LongPoll @config
    @transport.connect delay
    return

  stop: =>
    if @upgradeTimeout?
      clearTimeout @upgradeTimeout
      @upgradeTimeout = null
    @transport.stop()
    return

  _upgradeTransport: (ws) =>
    @transport.stop()
    ws.sendStartingMessageSequence @transport.getLastMessageSequence()
    @transport = ws
    return
<commit_msg>Log connection error instead of throwing exception if console is open - Do not completely die when console is open and websocket connection fails - See https://github.com/polleverywhere/firehose/issues/38<commit_after>class Firehose.Consumer
  constructor: (@config = {}) ->
    # Empty handler for messages.
    @config.message      ||= ->
    # Empty handler for error handling.
    @config.error        ||= ->
    # Empty handler for when we establish a connection.
    @config.connected    ||= ->
    # Empty handler for when we're disconnected.
    @config.disconnected ||= ->
    # The initial connection failed. This is probably triggered when a
    # transport, like WebSockets is supported by the browser, but for whatever
    # reason it can't connect (probably a firewall)
    @config.failed       ||= ->
      if console?
        console.log "Could not connect"
      else
        throw "Could not connect"
    # Params that we'll tack on to the URL.
    @config.params       ||= {}
    # Do stuff before we send the message into config.message. The sensible
    # default on the webs is to parse JSON.
    @config.parse        ||= JSON.parse
    # Make sure we return ourself out of the constructor so we can chain.
    this

  connect: (delay=0) =>
    @config.connectionVerified = @_upgradeTransport
    if Firehose.WebSocket.supported()
      @upgradeTimeout = setTimeout =>
        ws = new Firehose.WebSocket @config
        ws.connect delay
      , 500
    @transport = new Firehose.LongPoll @config
    @transport.connect delay
    return

  stop: =>
    if @upgradeTimeout?
      clearTimeout @upgradeTimeout
      @upgradeTimeout = null
    @transport.stop()
    return

  _upgradeTransport: (ws) =>
    @transport.stop()
    ws.sendStartingMessageSequence @transport.getLastMessageSequence()
    @transport = ws
    return

{'fraction_non_alphanumeric': 0.09037900874635568, 'fraction_numerical': 0.0029154518950437317, 'mean_word_length': 2.6577825159914714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6031575', 'n_tokens_mistral': 962, 'n_tokens_neox': 910, 'n_words': 325}