function getAllProxies(proxyListsModel){
let allProxies = [];
let cursor = proxyListsModel
.find({})
.sort({ rate: 'desc' })
.cursor();
await
cursor
.on('data', function (proxy) {
allProxies.push(proxy);
})
.on('error', function (err) {
console.log(err);
return false ;
})
.on('close', function () {
console.log('End');
return allProxies;
});
};
can you explain your question a little more? 😉
how can i await for this streaming getting data ? async function getAllProxies(proxyListsModel){ let allProxies = []; let cursor = proxyListsModel .find({}) .sort({ rate: 'desc' }) .cursor(); await cursor .on('data', function (proxy) { await allProxies.push(proxy); }) .on('error', function (err) { console.log(err); return false ; }) .on('close', function () { console.log('End'); return allProxies; }); };
promises will produce data once..i think you are looking for subscribe-push pattern or poll the data periodically
Обсуждают сегодня