【问题标题】:Waterline stream callback not reachable水线流回调无法访问
【发布时间】:2021-09-28 01:14:54
【问题描述】:

我无法使水线的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

【问题讨论】:

    标签: javascript sails.js waterline


    【解决方案1】:

    Waterline stream docs 没有帮助。在查看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")
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-19
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 1970-01-01
      • 2011-08-17
      相关资源
      最近更新 更多