criso / fbgraph

NodeJs module to access the facebook graph api
http://criso.github.io/fbgraph/
1.09k stars 176 forks source link

Support promises #74

Closed ksaitor closed 9 years ago

ksaitor commented 9 years ago

Would be awesome to have promises. E.g. with https://github.com/petkaantonov/bluebird

fbgraph
.get('/me', {
  access_token: access_token
})
.then(function (res) {
  console.log(res);
})
.catch(function (err) {
  console.error(err);
})

FTW!

tleunen commented 9 years ago

Here is what I use with bluebird:

var Promise = require("bluebird");
var Graph = require('fbgraph');
Promise.promisifyAll(Graph);

Then you can call functions like:

Graph.authorizeAsync()
Graph.getAsync()
Graph.batchAsync()
...

Hope it helps :)

ksaitor commented 9 years ago

Thanks @tleunen. I actually did that in my project, a while ago. However, realised that some devs might not be aware that Bluebird and promisifyAll exist, hence built in promises might be handy. No?

criso commented 9 years ago

How about a section in the docs on how to add bluebird to it? If it can be done with promisifyAll, adding it to the the lib seems unnecessary