time ::
     Int
     -- ^ the initial delay in milliseconds
  -> Int
     -- ^ the number of collisions that have occurred
  -> Int
time initialDelayMs collisions =
    initialDelayMs * ((2 ^ collisions) - 1) * numMicrosecondsInMillisecond
  where
    numMicrosecondsInMillisecond :: Int
    numMicrosecondsInMillisecond = 1000

{- |
  We default the maximum backoff exponent to 11 and initial delay to 10ms, which
  translates to a 20.47 second delay. Specifying a higher maximum is useful for
  platforms that enforce a long waiting-period when a rate-limit is exceeded.

  backoff   time
  -------  -------
     0       0.0 (seconds)
     1      0.01
     2      0.03
     3      0.07
     4      0.15
     5      0.31
     6      0.63
     7      1.27
     8      2.55
     9      5.11
    10     10.23
    11     20.47
    12     40.95

    13      1.36 (minutes)
    14      2.73
    15      5.46
    16     10.92
    17     21.84
    18     43.69

    19      1.45 (hours)
-}


{- |
  A coordinating manager for rate limiting.
-}
time ::
     Int
     -- ^ the initial delay in milliseconds
  -> Int
     -- ^ the number of collisions that have occurred
  -> Int
time initialDelayMs collisions =
    initialDelayMs * ((2 ^ collisions) - 1) * numMicrosecondsInMillisecond
  where
    numMicrosecondsInMillisecond :: Int
    numMicrosecondsInMillisecond = 1000

{- |
  We default the maximum backoff exponent to 11 and initial delay to 10ms, which
  translates to a 20.47 second delay. Specifying a higher maximum is useful for
  platforms that enforce a long waiting-period when a rate-limit is exceeded.

  backoff   time
  -------  -------
     0       0.0 (seconds)
     1      0.01
     2      0.03
     3      0.07
     4      0.15
     5      0.31
     6      0.63
     7      1.27
     8      2.55
     9      5.11
    10     10.23
    11     20.47
    12     40.95

    13      1.36 (minutes)
    14      2.73
    15      5.46
    16     10.92
    17     21.84
    18     43.69

    19      1.45 (hours)
-}


{- |
  A coordinating manager for rate limiting.
-}
time initialDelayMs collisions =
    initialDelayMs * ((2 ^ collisions) - 1) * numMicrosecondsInMillisecond
  where
    numMicrosecondsInMillisecond :: Int
    numMicrosecondsInMillisecond = 1000

{- |
  We default the maximum backoff exponent to 11 and initial delay to 10ms, which
  translates to a 20.47 second delay. Specifying a higher maximum is useful for
  platforms that enforce a long waiting-period when a rate-limit is exceeded.

  backoff   time
  -------  -------
     0       0.0 (seconds)
     1      0.01
     2      0.03
     3      0.07
     4      0.15
     5      0.31
     6      0.63
     7      1.27
     8      2.55
     9      5.11
    10     10.23
    11     20.47
    12     40.95

    13      1.36 (minutes)
    14      2.73
    15      5.46
    16     10.92
    17     21.84
    18     43.69

    19      1.45 (hours)
-}


{- |
  A coordinating manager for rate limiting.
-}