From f037e962c647dc13c08cd0994d7c3299f1138de8 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Thu, 8 Aug 2024 17:54:09 +0000 Subject: [PATCH] Accept Thenables as a collect() hander. --- lib/counter.js | 2 +- lib/gauge.js | 2 +- lib/histogram.js | 2 +- lib/summary.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/counter.js b/lib/counter.js index 39a7bd1b..8ca56208 100644 --- a/lib/counter.js +++ b/lib/counter.js @@ -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 { diff --git a/lib/gauge.js b/lib/gauge.js index 3725bf01..e1134f26 100644 --- a/lib/gauge.js +++ b/lib/gauge.js @@ -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, diff --git a/lib/histogram.js b/lib/histogram.js index 539620c2..fda2fc9e 100644 --- a/lib/histogram.js +++ b/lib/histogram.js @@ -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 diff --git a/lib/summary.js b/lib/summary.js index 28fdb07a..9db8d2c4 100644 --- a/lib/summary.js +++ b/lib/summary.js @@ -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 = [];