mirror of
https://github.com/baz-scm/awesome-reviewers.git
synced 2025-08-20 18:58:52 +03:00
1.4 KiB
1.4 KiB
title, description, repository, label, language, comments_count, repository_stars
| title | description | repository | label | language | comments_count | repository_stars |
|---|---|---|---|---|---|---|
| Standardize API promise patterns | When adding promise support to API methods, implement a consistent pattern that handles both callback-style and multi-parameter methods. Use a standardized promisification approach that appends the promise-determining callback as the last argument. | aws/aws-sdk-js | API | Javascript | 2 | 7628 |
When adding promise support to API methods, implement a consistent pattern that handles both callback-style and multi-parameter methods. Use a standardized promisification approach that appends the promise-determining callback as the last argument.
Example implementation:
function promisifyMethod(methodName, PromiseDependency) {
return function promise() {
var self = this;
var args = Array.prototype.slice.call(arguments);
return new PromiseDependency(function(resolve, reject) {
args.push(function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
self[methodName].apply(self, args);
});
};
}
This pattern ensures:
- Consistent promise behavior across all API methods
- Support for both simple callback methods and multi-parameter methods
- Proper error handling and promise rejection
- Compatibility with different promise implementations