水线流回调无法访问

Waterline stream callback not reachable

我无法让水线的 stream 工作。我正在关注 stream docs.

我使用 stream 正确吗?

MyModel.stream({ isSubscribed: true }).populate("user").eachBatch(10, function(err, records){
   console.log("Code reached inside stream results")
})
// Output: Prints nothing

虽然 find 功能运行良好

MyModel.find({ isSubscribed: true }).populate("user").exec(function(err, records){
   console.log("Found "+ records.length+ " records")
})
// Output: Prints "Found 12 records"

更新:该问题似乎特定于 eachBatch 函数。不确定到底是什么,但测试 eachRecord 确实有效。

await MyModel.stream({ isSubscribed: true }).populate("user").eachRecord(async function(record){
   console.log("Code reached inside stream results")
})
// Output: Code reached inside stream results

Waterline stream docs were not helpful. After looking into waterline code for stream 我按如下方式编辑我的代码并且它起作用了,即现在可以访问 eachBatch 回调中的代码

MyModel.stream({ 
    isSubscribed: true 
}).eachBatch(function(records, next){ 
    console.log("Reachable!! Found records: ", records); 
    next(); 
}).exec(function(err){
   console.log("Done with stream query")
})