N
N
Neuro2019-04-26 13:19:57
JavaScript
Neuro, 2019-04-26 13:19:57

How to change new Promise to util.promisify?

How can this function be rewritten to util.promisify?

Location.getLocationByUrlSlugWithPromise = function(urlSlug) {
    return new Promise((resolve, reject) => {
      Location.getLocationByUrlSlug(urlSlug, (error, location) => {
        if (error) {
          return reject(error);
        }
        if (location) {
          return resolve(location);
        }

        return relose(null);
      });
    })
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2019-04-26
@Riveran

Something like this:

Location.getLocationByUrlSlugWithPromise = util.promisify(Location.getLocationByUrlSlug.bind(Location));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question