Skip to content

Commit

Permalink
♻️ Make Base#callOrNext(name, args, next) handle methods without ca…
Browse files Browse the repository at this point in the history
…llbacks
  • Loading branch information
skerit committed Oct 19, 2023
1 parent 2bfc8d5 commit a6ff810
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.20 (WIP)

* Make `Base#callOrNext(name, args, next)` handle methods without callbacks

## 1.3.19 (2023-10-18)

* Fix `Conduit#parseUrl()` not being able to parse the host & protocol of http2 requests
Expand Down
23 changes: 19 additions & 4 deletions lib/core/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,11 @@ Base.setMethod(function getClassPathAfter(after) {
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.0.0
* @version 1.2.2
* @version 1.3.20
*
* @param {String} name The name of the method to call
* @param {Array} args The arguments to pass
* @param {Function} next The callback to call afterwards
*/
Base.setMethod(function callOrNext(name, args, next) {

Expand All @@ -480,14 +484,25 @@ Base.setMethod(function callOrNext(name, args, next) {
args = [];
}

if (typeof this[name] == 'function') {
const fnc = this[name];

if (typeof fnc == 'function') {

let has_callback = false,
promise;

if (next) {
if (next && fnc.length > args.length) {
has_callback = true;
args.push(next);
}

try {
this[name].apply(this, args);
promise = this[name].apply(this, args);

if (!has_callback) {
Pledge.done(promise, next);
}

} catch (err) {
next(err);
}
Expand Down

0 comments on commit a6ff810

Please sign in to comment.