Skip to content

Commit

Permalink
Accept Thenables as a collect() hander.
Browse files Browse the repository at this point in the history
  • Loading branch information
farcaller committed Aug 8, 2024
1 parent c1d76c5 commit f037e96
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Counter extends Metric {
async get() {
if (this.collect) {
const v = this.collect();
if (v instanceof Promise) await v;
if ((v instanceof Promise) || (v.then instanceof Function)) await v;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion lib/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Gauge extends Metric {
async get() {
if (this.collect) {
const v = this.collect();
if (v instanceof Promise) await v;
if ((v instanceof Promise) || (v.then instanceof Function)) await v;
}
return {
help: this.help,
Expand Down
2 changes: 1 addition & 1 deletion lib/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Histogram extends Metric {
async getForPromString() {
if (this.collect) {
const v = this.collect();
if (v instanceof Promise) await v;
if ((v instanceof Promise) || (v.then instanceof Function)) await v;
}
const data = Object.values(this.hashMap);
const values = data
Expand Down
2 changes: 1 addition & 1 deletion lib/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Summary extends Metric {
async get() {
if (this.collect) {
const v = this.collect();
if (v instanceof Promise) await v;
if ((v instanceof Promise) || (v.then instanceof Function)) await v;
}
const hashKeys = Object.keys(this.hashMap);
const values = [];
Expand Down

0 comments on commit f037e96

Please sign in to comment.