这个错误函数的目的是什么 "next(err, err || doc._id)"

What is the purpose of this err function "next(err, err || doc._id)"

我试图了解以下函数中发生的情况:

   next(err, err || doc._id) 

我对此进行了一些研究,但找不到任何解释 next 函数的文档。有人能解释一下它的用途吗?

function createQuestions(storyPrettyId, questions, author, callback) {
    async.map(
        questions,
        function(question, next) {
            QuestionMongoModel.create({
                storyPrettyId: storyPrettyId,
                title: question.title,
                answers: question.answers,
                author: author
            }, function(err, doc) {
                next(err, err || doc._id)
            })
        }, 
        callback
    )
}

答案在 async.map() 的文档中:

Arguments

  • arr - An array to iterate over.
  • iterator(item, callback) - A function to apply to each item in arr. The iterator is passed a callback(err, transformed) which must be called once it has completed with an error (which can be null) and a transformed item.
  • callback(err, results) - Optional A callback which is called when all iterator functions have finished, or an error occurs. Results is an array of the transformed items from the arr.

next 只是您传递给 async.map()iterator() 函数的 callback 参数。