1

I'm trying to call Bluebird promisificator on https://github.com/seishun/node-steam-trade, but this library is using non-node-callbacks.

For example (ES6 syntax by Babel):

import bluebird from 'bluebird';
import SteamTrade from 'steam-trade';

bluebird.promisifyAll(SteamTrade.prototype);

let steamTrade = new SteamTrade();

// some kind of set sessionid/cookies

let result = await steamTrade.openAsync('my-steam-id');

And last row is not finish, because first argument, passed into callback is "data", not error (docs).

How can I configure bluebird to handle data from first argument?

  • 1
    Try a [custom promisifier](http://bluebirdjs.com/docs/api/promise.promisifyall.html). – Bergi May 16 '16 at 20:22
  • possible duplicate of [How do I convert an existing callback API to promises?](http://stackoverflow.com/q/22519784/1048572) – Bergi May 16 '16 at 20:22

1 Answers1

0

You may want to use when.js (https://github.com/cujojs/when/blob/master/docs/api.md#whenlift)

Or you can write your own Promise wrapper.

steamTrade.openAsync = function(id){
  var promise = new bluebird( function(resolve, reject){
    steamTrade.open(id, function(data){ resolve(data); });
  });
  return promise;
};
memimomu
  • 161
  • 4