summaryrefslogtreecommitdiff
path: root/test/lib/promise.js
blob: d2afe09c8a0c241a47a1bf8de6f96b07630e3d3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = function(fn, data){
  var my_cb, my_res
  data.success = function(res){
    my_res = res
    if (my_cb) {
      my_cb(res)
    }
  }
  data.error = function(res){
    console.log('error!')
    console.log(res)
  }
  fn(data)
  var promise = {
    then: function(cb){
      if (my_res) cb(my_res)
      else my_cb = cb
    }
  }
  return promise
}