javascriptsails.jswaterline

Waterline stream callback not reachable


I can't make waterline's stream work. I'm following stream docs.

Am I using stream correctly?

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

While the find function works very well

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

Update: The issue seems to be specific to eachBatch function. Not sure exactly what but tested eachRecord and that did work.

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

Solution

  • Waterline stream docs were not helpful. After looking into waterline code for stream I edited my code as following and it worked i.e. the code inside the eachBatch callback is reachable now

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