**Exponential Backoff Delay** [Napier / Dash Automation, LLC] So I needed an exponential backoff delay for reconnecting to our Websocket Server when our servers go down. I decided to implement it using a simple coroutine and the "redelay" command (reconnect delay). Exponential Backoff is used to schedule reconnects to a server so that when your server connection is re-established every instance of your scripts won't reconnect at the same exact time. If you want to learn more I found http://blog.johnryding.com/post/78544969349/how-to-reconnect-web-sockets-in-a-realtime-web-app%|%this blog post%|% to be very helpful. ====== namespace eval redelay { variable count 0 } proc redelay { {name {}} {max 30} } { if {$name eq {}} { append name ::redelay::task [incr ::redelay::count] } return [coroutine $name ::redelay::delay $max] } proc ::redelay::delay { max } { yield [info coroutine] set attempts 1 while 1 { set interval [expr { min($max, (pow(2, $attempts) - 1)) * 1000 }] set delay [expr { int(rand()*($interval-1+1)+1) }] incr attempts if {[yield $delay] ne {}} { return } } } ====== <>delay | exponential backoff