4 using System.Collections.Generic;
8 internal class LeakyBucket
10 private readonly Queue<Action> queue;
11 private readonly
int capacity;
12 private readonly
float cooldownInSeconds;
15 public LeakyBucket(
float cooldownInSeconds,
int capacity)
17 this.cooldownInSeconds = cooldownInSeconds;
18 this.capacity = capacity;
19 queue =
new Queue<Action>(capacity);
22 public void Update(
float deltaTime)
30 if (queue.Count is 0) {
return; }
35 private void TryDequeue()
37 timer = cooldownInSeconds;
38 if (queue.TryDequeue(out var action))
44 public bool TryEnqueue(Action item)
46 if (queue.Count >= capacity) {
return false; }