I have a spec from a client for an implementation of a method in a module:
// getGenres():
// Returns a promise. When it resolves, it returns an array.
If given an array of genres,
['comedy', 'drama', 'action']
Here is a skeleton method with a promise:
MovieLibrary.getGenres = function() {
var promise = new Promise(function(resolve, reject) {
/* missing implementation */
});
return promise;
};
Can the promise be made to return the data found in the genres? Is there a better way to achieve the spec description?
resolve([genre1, genre2, ...]);
inside the promise implementation.Promise.catch
. In case of usingasync
/await
syntax one should use thetry-catch
block to enclose the awaited statement(s). Note there is also aPromise.finally
.