aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/nodeify.js
blob: 56b79385260b48101a7113449dfa71d6ebcd2bcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module.exports = function (promiseFn) {
  return function () {
    var args = []
    for (var i = 0; i < arguments.length - 1; i++) {
      args.push(arguments[i])
    }
    var cb = arguments[arguments.length - 1]

    return promiseFn.apply(this, args)
    .then(function (result) {
      cb(null, result)
    })
    .catch(function (reason) {
      cb(reason)
    })
  }
}