       hyperclientDestroy hc
       sequence_ $ Map.elems handles 
       putMVar c (Nothing, Map.empty)
+
+doExponentialBackoff :: Int -> Double -> (Int, BackoffMethod)
+doExponentialBackoff b x = 
+  let result = ceiling (fromIntegral b ** x) in
+    (result, BackoffExponential result x)
+
+cappedBackoff :: Int -> Maybe Int -> (Int, Bool)
+cappedBackoff n Nothing = (n, False)
+cappedBackoff n (Just c) | n  < c  = (n, False)
+                         | n >= c  = (c, True)
+
+performBackoff :: BackoffMethod -> Maybe Int -> IO (BackoffMethod)
+performBackoff method cap = do
+  let (delay, newBackoff) = case method of
+            BackoffYield      -> (0, method)
+            BackoffConstant n -> (0, method)
+            BackoffLinear m b -> (m, BackoffLinear (m+b) b)
+            BackoffExponential b x -> doExponentialBackoff b x
+      (backoff, capped) = cappedBackoff delay cap
+  let delay = case backoff of
+                0 -> yield
+                n -> threadDelay n
+      next  = case capped of
+                True  -> BackoffConstant backoff
+                False -> newBackoff
+  delay >> return next
 
 -- | Runs hyperclient_loop exactly once, setting the appropriate MVar.
 loopClient' :: Bool -> Client -> IO (Maybe Handle)

          v <- newEmptyMVar :: IO (MVar (Either ReturnCode a))
          putMVar c (Just hc, Map.insert h (cont >>= putMVar v) handles)
          return $ do
            _ <- loopClientUntil client h Nothing v 
            res <- peekMVar v
            return $ fromMaybe (error "This should not occur!") res
        False -> do

--
-- All integer values are in microseconds.
data BackoffMethod
  -- | No delay is used except the thread is yielded.
  = BackoffYield
  -- | Delay a constant number of microseconds each inter.
  | BackoffConstant Int
  -- | Delay with an initial number of microseconds, increasing linearly by the second value. 
