     else if @_lastIdx < idx
       @_lastIdx = idx
 
-    rowPromise
-    .then (row) =>
-      @_incommingRow idx, row, d
-    .fail (error) ->
-      d.reject error
-    .done()
-
-    d.promise
-
-  _incommingRow: (idx, row, defer) ->
-    @_buffer["#{idx}"] = {idx: idx, row: row, defer: defer}
+    [d.promise, @_incommingRow idx, rowFn, d]
+
+  _incommingRow: (idx, rowFn, defer) ->
+    @_buffer["#{idx}"] = {idx: idx, row: rowFn, defer: defer}
 
     @_checkWhetherFinished()
 
   _checkWhetherFinished: () ->
     if not @_written and @_finished and @_allRowsFinished()
-      _.each @_getIdxs(), (idx) =>
+      @_written = true
+
+      ps = _.map @_getIdxs(), (idx) =>
         box = @_buffer["#{idx}"]
-        box.defer.resolve box.row
-      @_written = true
+
+        box.row()
+        .then (row) ->
+          box.defer.resolve row
+        .fail (error) ->
+          box.defer.reject error
+          Q.reject error
+
+      Q.all ps
+      .then ->
+        true
+    else
+      Q(false)
 
   _allRowsFinished: () ->
     _.every @_getIdxs(), (idx) =>

        .fail (error) ->
          done error, null
        .done()
        lastBufferGroupValue = groupValue
    .on 'end', (count) ->
      if lastBufferGroupValue?
        buffers[lastBufferGroupValue].finished()

      d.resolve(count)
    .on 'error',
      (error) -> d.reject(error)


  getFirstIndex: () ->
    @_firstIdx

  add: (idx, rowFn) ->
    d = Q.defer()

    if not @_firstIdx?
