RE: RE: CSC v1
You are viewing a single comment's thread from:

RE: CSC v1

Words
58
Reading
1 min
Listen
Play
9y

const promisify = func => {
// this need to not using arrow function, otherwise the this context will be wrong
return function() {
const args = Array.from(arguments);

return new Promise((resolve, reject) => {
  const callback = (err, data) => {
    if (error) {
      return reject(err);
    }

    return resolve(data);
  };

  args.push(callback);

  func.apply(this, args);
});

};
}

API.someAsyncFunc = promisify(someAsyncFunc)

@norther: const promisify | Ecency