Skip to content

Commit

Permalink
Priority queue ram_duration/1 should be the minimum of sub-queues', n…
Browse files Browse the repository at this point in the history
…ot the sum. (References #67)
  • Loading branch information
Simon MacMullen committed Mar 13, 2015
1 parent 17a5da8 commit be901c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/rabbit_priority_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ set_ram_duration_target(DurationTarget,
?passthrough1(set_ram_duration_target(DurationTarget, BQS)).

ram_duration(State = #state{bq = BQ}) ->
fold_add2(fun (_P, BQSN) -> BQ:ram_duration(BQSN) end, State);
fold_min2(fun (_P, BQSN) -> BQ:ram_duration(BQSN) end, State);
ram_duration(State = #passthrough{bq = BQ, bqs = BQS}) ->
?passthrough2(ram_duration(BQS)).

Expand Down Expand Up @@ -459,6 +459,13 @@ fold_add2(Fun, State) ->
{add_maybe_infinity(Res, Acc), BQSN1}
end, 0, State).

%% Fold over results assuming results are numbers and we want the minimum
fold_min2(Fun, State) ->
fold2(fun (P, BQSN, Acc) ->
{Res, BQSN1} = Fun(P, BQSN),
{erlang:min(Res, Acc), BQSN1}
end, infinity, State).

%% Fold over results assuming results are lists and we want to append
%% them, and also that we have some AckTags we want to pass in to each
%% invocation.
Expand Down

0 comments on commit be901c1

Please sign in to comment.