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; } }