Promisify a function which returns null

This function returns null and I need to promisify it. but I don't understand this code. Can anyone help with this.

return iyzipay.payment.create(req, function (err, result) {
    return('result:'+ result + 'error:'+ err);
})

Upvotes: 0

Views: 79

Answers (1)

Marco
Marco

Reputation: 7287

Wrap your code in a Promise and call either resolve or reject once the operation is completed.

return new Promise(function(resolve, reject) {
    iyzipay.payment.create(req, function (err, result) {
        if (err) {
            reject(err)
        } else {
            resolve(result)
        }
    })
})

Upvotes: 1

Related Questions