   
         
 exports.Tail = Tail
+

      @internalDispatcher.emit("next") if @queue.length is 1
  
  unwatch: ->
    if fs.watch
      @watcher.close()
      @pos = 0
    else fs.unwatchFile @filename

  watch: ->
    return if @isWatching
    @isWatching = true
    #if fs.watch then @watcher = fs.watch @filename, @fsWatchOptions, (e) => @watchEvent e
    fs.watchFile @filename, @fsWatchOptions, (curr, prev) => @watchFileEvent curr, prev
  
  #concurrency problem introduced by @pos; need to solve this before being able to use watch instead of watchFile
  watchEvent:  (e) ->
      if e is 'change'
        fs.stat @filename, (err, stats) =>
          @emit 'error', err if err
          if stats.size > @pos
            @queue.push({start: @pos, end: stats.size})
            @internalDispatcher.emit("next") if @queue.length is 1
      else if e is 'rename'
        @unwatch()
        setTimeout (=> @watch()), 1000
  
  watchFileEvent: (curr, prev) ->
    if curr.size > prev.size
