From 9f74cea83dc41c4cd8317b7e0c23d5804def20a8 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Tue, 18 Dec 2018 15:38:15 -0800 Subject: [PATCH] Defer initial report (#56) If adding several metrics at once, on the same interval, only the first will be reported in the initial report due to the immediate call to `reporter._reportMetricsWithInterval(...)`. By wrapping that in a `setImmediate(...)`, any other metrics set in that tick should now also be included in the initial report. --- packages/measured-reporting/lib/reporters/Reporter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/measured-reporting/lib/reporters/Reporter.js b/packages/measured-reporting/lib/reporters/Reporter.js index 9d186ef..a042e84 100644 --- a/packages/measured-reporting/lib/reporters/Reporter.js +++ b/packages/measured-reporting/lib/reporters/Reporter.js @@ -138,8 +138,10 @@ class Reporter { this._intervalToMetric[intervalInSeconds].add(metricKey); } else { this._intervalToMetric[intervalInSeconds] = new Set([metricKey]); - this._reportMetricsWithInterval(intervalInSeconds); this._createIntervalCallback(intervalInSeconds); + setImmediate(() => { + this._reportMetricsWithInterval(intervalInSeconds); + }); } }