Skip to content

Commit

Permalink
feat(promises): Support monitoring for functions that don't invoke IO…
Browse files Browse the repository at this point in the history
…pipe callback

Invoking IOpipe callback for wrapped functions that don't invoke it themselves. (Merges pull request #335 from mrickard/issue/handle-promises)
  • Loading branch information
mrickard authored Jul 5, 2019
2 parents 9538b99 + 4cd7fda commit 749c2b9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,21 @@ class IOpipeWrapperClass {
invoke() {
this.runHook('pre:invoke');
try {
return this.userFunc.call(
const result = this.userFunc.call(
this.originalIdentity,
this.event,
this.context,
this.callback
);
if (result && result.then && result.catch) {
return new Promise(() => this.callback(null, () => result))
.then(value => value)
.catch(err => {
this.sendReport(err, () => this.originalCallback(err));
return err;
});
}
return result;
} catch (err) {
this.sendReport(err, () => this.originalCallback(err));
return err;
Expand Down

0 comments on commit 749c2b9

Please sign in to comment.