Exponential Backoff Idiom

Eric Newhuis enewhuis@REDACTED
Sat Feb 13 18:24:30 CET 2010


Sorry for that.  This is what I intended to post:

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

On Feb 13, 2010, at 11:22 AM, Eric Newhuis wrote:

> 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