From 6865f0a1965da434505a33f667142de5ed4f8ddd Mon Sep 17 00:00:00 2001 From: david Date: Wed, 15 Jul 2026 19:37:51 +0200 Subject: [PATCH] Append flushes instead of setting them in `Metrics.Factory#onFlush` --- core/src/main/java/dev/faststats/Metrics.java | 2 +- core/src/main/java/dev/faststats/SimpleMetrics.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/dev/faststats/Metrics.java b/core/src/main/java/dev/faststats/Metrics.java index 49715fe8..6fe7c503 100644 --- a/core/src/main/java/dev/faststats/Metrics.java +++ b/core/src/main/java/dev/faststats/Metrics.java @@ -29,7 +29,7 @@ interface Factory { Factory addMetric(Metric metric) throws IllegalArgumentException; /** - * Sets the flush callback for this metrics instance. + * Adds a flush callback to this metrics instance. *

* This callback will be invoked when the metrics have been submitted to, and accepted by, the metrics server. * diff --git a/core/src/main/java/dev/faststats/SimpleMetrics.java b/core/src/main/java/dev/faststats/SimpleMetrics.java index cb8fbd63..a798a96c 100644 --- a/core/src/main/java/dev/faststats/SimpleMetrics.java +++ b/core/src/main/java/dev/faststats/SimpleMetrics.java @@ -136,7 +136,13 @@ public Factory addMetric(final Metric metric) throws IllegalArgumentException @Override public Factory onFlush(final Runnable flush) { - this.flush = flush; + final var runnable = this.flush; + if (runnable == null) { + this.flush = flush; + } else this.flush = () -> { + runnable.run(); + flush.run(); + }; return this; } }