[使用mysql中的流在经过一定次数后退出

问题描述 投票:0回答:1

下面是我的代码,它在5次迭代后退出。我无法弄清楚为什么它只能运行5次并在此之后退出。我的表中有更多数据。

    function AddDataSync() {
        var query=connection.query('select officename, divisionname from table').
        stream()
        .pipe(stream.Transform({
    objectMode: true,
    transform: function(data,encoding,callback) {
      // do something with data...
        connection.pause();
        googleMapsClient.geocode({
               address: data.officename+' '+data.divisionname
                }, function(err, response) {
          if (!err) {
            console.log(response.json.results[0].geometry.location);
            connection.resume();
            callback();
          }
          else {
            console.log(err);
            connection.resume();
          }
        });
    }
   })).on('finish',function() { console.log('done');});
}
mysql node.js geocoding
1个回答
0
投票

我想即使在您的else块中,您也应该调用callback();,否则,该流将被阻塞。

© www.soinside.com 2019 - 2024. All rights reserved.