diff --git a/examples/rate-limiting/rate-limiting.hash b/examples/rate-limiting/rate-limiting.hash index 3b65732..9d7eb4f 100644 --- a/examples/rate-limiting/rate-limiting.hash +++ b/examples/rate-limiting/rate-limiting.hash @@ -1,2 +1,2 @@ -4f327f5bd5ac199ae5590652563ea6ca4ce7eff5 -lqf7pC2FUeT +79547a5eac4239581488a8a536e5379819ab839e +gv2VaeN0wi1 diff --git a/public/rate-limiting b/public/rate-limiting index 4ce31db..c991b19 100644 --- a/public/rate-limiting +++ b/public/rate-limiting @@ -45,7 +45,7 @@ channels, and tickers.

- +
package main
@@ -151,14 +151,19 @@ channel will allow bursts of up to 3 events.

Every 200 milliseconds we’ll try to add a new -value to burstyLimiter, up to its limit of 3.

+value to burstyLimiter, up to its limit of 3. +If there is no space left then we continue.

    go func() {
         for t := range time.Tick(200 * time.Millisecond) {
-            burstyLimiter <- t
+            select {
+            case burstyLimiter <- t:
+            default:
+                continue
+            }
         }
     }()
@@ -239,7 +244,7 @@ then serve the remaining 2 with ~200ms delays each.