+-spec produce_sync(state()) ->
+ state().
+produce_sync(#state{}=State) ->
+ produce(State, fun beam_stats_consumer:consume_sync/2).
+
+-spec produce_async(state()) ->
+ state().
+produce_async(#state{}=State) ->
+ produce(State, fun beam_stats_consumer:consume_async/2).
+
+-spec produce(state(), fun((pid(), term()) -> ok)) ->
+ state().
+produce(
+ #state
+ { consumers = ConsumersSet
+ , stats_state = StatsState1
+ }=State,
+ MsgSendFun
+) ->
+ StatsState2 = beam_stats_state:update(StatsState1),
+ Stats = beam_stats_state:export(StatsState2),
+ ConsumersList = ordsets:to_list(ConsumersSet),
+ Send = fun (Consumer) -> MsgSendFun(Consumer, Stats) end,
+ ok = lists:foreach(Send, ConsumersList),
+ State#state{stats_state = StatsState2}.
+