Example #1
0
        public static async Task SendWithBackOff(IEnv env, int recipient, object msg)
        {
            var counter = 0;

            while (true)
            {
                try {
                    await env.Send(recipient, msg);

                    return;
                } catch (Exception ex) {
                    if (counter < 10)
                    {
                        counter++;
                        var sleep = TimeSpan.FromSeconds(Math.Pow(2, counter));
                        env.Debug($"Retrying send on {ex.Message} #{counter} after {sleep.TotalSeconds} seconds");
                        await env.Delay(sleep);

                        continue;
                    }

                    throw;
                }
            }
        }