es2015/object-store/AbstractBaseStorage.js
function iterateCursor(request, cursorConstructor, recordCallback) {
  return new PromiseSync((resolve, reject) => {
    let traversedRecords = 0
    let canIterate = true
    
    request.onerror = () => reject(request.error)
    request.onsuccess = () => {
      if (!canIterate) {
        console.warn("Cursor iteration was requested asynchronously, " +
            "ignoring the new cursor position")
        return
      }
      
      if (!request.result) {
        resolve(traversedRecords)
        return
      }
      
      traversedRecords++
      
      let iterationRequested = handleCursorIteration(
        request,
        cursorConstructor,
        recordCallback,
        reject
      )
      
      if (!iterationRequested) {
        canIterate = false
        resolve(traversedRecords)
      }
    }
  })
}
function iterateCursor(request, cursorConstructor, recordCallback) {
  return new PromiseSync((resolve, reject) => {
    let traversedRecords = 0
    let canIterate = true
    
    request.onerror = () => reject(request.error)
    request.onsuccess = () => {
      if (!canIterate) {
        console.warn("Cursor iteration was requested asynchronously, " +
            "ignoring the new cursor position")
        return
      }
      
      if (!request.result) {
        resolve(traversedRecords)
        return
      }
      
      traversedRecords++
      
      let iterationRequested = handleCursorIteration(
        request,
        cursorConstructor,
        recordCallback,
        reject
      )
      
      if (!iterationRequested) {
        canIterate = false
        resolve(traversedRecords)
      }
    }
  })
}
Iterates the cursor to which the provided Indexed DB request resolves. The
method will iterate the cursor over the records in this storage within the
range specified when the cursor was opened until the provided callback does
not request iterating to the next record or the last matching record is
reached.

@param {IDBRequest} request Indexed DB request that resolves to a cursor
every time the cursor iterates to a record.
@param {function(new: ReadOnlyCursor, IDBRequest, function(), function(IDBRequest): PromiseSync)} cursorConstructor
Constructor of the cursor class to use to wrap the native IDBRequest
producing the native IndexedDB cursor.
@param {function(ReadOnlyCursor)} recordCallback The callback to execute,
passing a high-level cursor instance pointing to the current record
in each iteration of the cursor.
@return {PromiseSync<number>} A promise that resolves to the number of
records the cursor traversed.