Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2119

Cursor.forEach should handle async callback

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: next
    • Component/s: Core
    • Labels:
    • Environment:
      Ubuntu Linux 18.04 latest

      Right now if you specify an async function as the callback for a Cursor.forEach, not all off the callbacks will execute, since forEach doesn't recognize that the callback returned a Promise.

      Use case:

       

      Doing a Cursor.forEach on a parent collection, but inside the callback you want to do a child.findOne() to do some additional things. The findOne is async....but if you do an await on the findOne, it means you have to tag the forEach callback as async and then later callbacks are not guaranteed to ever complete.

      It would be great if forEach detected if a callback returned a Promise and if so, waited for that Promise to complete before iterating to the next document in the Cursor.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ataramina@shorecg.com Andrzej Taramina
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: