Search code examples
javascriptloopback

Convert call back to promise


I am trying to convert one loopback callback function to promise, but I am not able to convert it. The code for is

let ds = app.datasources.ace_db
ds.connector.execute(sql,[],(err, data ) => {
   console.log('datalogger', data);
});

Is there any method to convert this peace of code to promise?


Solution

  • You could do a Promise.promisify()

    let p = Promise.promisify(ds.connector.execute);
    p(sql, []).then(...)