0

I want to read large text file and check number at each line in my redis database so basically i have to async/await my redis command below given is my code i tried to use event-stream

function readFile()
{
return new Promise(function (resolve, reject) {
let totalLines = 0;
var s=fs.createReadStream("/var/www/uploads/"+filename);
    s.pipe(es.split())
    .pipe(
        es.map(function (line, cb) {
            cb(customFunction(line))
        })
            .on("error", function (err) {
                reject(err);
            })
            .on("end", function () { 
              resolve("ok");
            })
    );
})
}

function customFuntion(line){
 async()=>{
 var res=await redisClient.get(line);
 console.log(res)  
 }();
}

the issue is code doesn't wait for redis result instead it resolves the promise of readFile function before redis result is displayed

Benson OO
  • 477
  • 5
  • 22
  • This lacks details and includes code that isn't relevant to the question. What is `es`? Why is `totalLines` here? Please revise the question to make it closer to a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – jorgenkg Mar 23 '22 at 17:57
  • @jorgenkg is the instance of event-stream package and the code shared here is totally relevant to the question asked – Benson OO Mar 23 '22 at 19:06

0 Answers0