clonn / slack-node-sdk

slack.com, slack, node sdk
MIT License
167 stars 32 forks source link

return es6 promise #3

Closed poying closed 8 years ago

poying commented 9 years ago

then we can do:

slack
  .webhook({
    channel: "#general",
    username: "webhookbot",
    text: "This is posted to #general and comes from a bot named webhookbot."
  })
  .then(function (res) {
    // ...
  })
  .catch(function (err) {
    // ...
  });

and

var res = yield slack.webhook({
  channel: "#general",
  username: "webhookbot",
  text: "This is posted to #general and comes from a bot named webhookbot."
});
poying commented 9 years ago

@clonn @tomchentw

There is a way to support es6 promise and we don't need to change the existing interface:

var callbackOrPromise = function (cb, fn) {
  if (cb || typeof Promise === 'undefined') {
    return fn(cb);
  }
  return new Promise(function (resolve, reject) {
    fn(function (err, res) {
      err ? reject(err) : resolve(res);
    });
  });
};
webhook: (options, callback) =>
  return callbackOrPromise
    callback
  , (callback) =>
      # ...
tomchentw commented 9 years ago

:+1:

kevinburkeshyp commented 9 years ago

hey, any update or further thoughts here?

seawatts commented 8 years ago

It says this was released in version 0.1.6 however I don't see it in there.

georgerichmond commented 8 years ago

+1

kevinburkeshyp commented 8 years ago

reading the commit history, I'm not sure this was implemented, unfortunately. gonna close this for now - feel free to implement/send a PR, or wrap via Promise.promisify in your own code base