Exponential Backoff Idiom

Eric Newhuis <>
Sat Feb 13 18:22:34 CET 2010


Has anyone a better version of this they'd like to share?  The trouble with this approach is that Fun cannot block.  Maybe there is an entirely better way to express this so it works as a mix-in concept whether or not Fun has its own receive loop.  I wrote this expecting it would not.

backoff(N, Multiplier, Max, Fun, Acc) ->
		case Fun(Acc) of
				{continue, Acc2} ->
						receive
						after
								N ->
										discover(?IF(N < Max, N*Multiplier, Max))
						end;
				{ok, Acc2} ->
						Acc2
		end.



More information about the erlang-questions mailing list