Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Last active June 21, 2018 23:13
Show Gist options
  • Save JohnMurray/205f46ce35e514dadc5559aa02b6d1f8 to your computer and use it in GitHub Desktop.
Save JohnMurray/205f46ce35e514dadc5559aa02b6d1f8 to your computer and use it in GitHub Desktop.
class ApiService[T] {
// other code ...
def request(f: () => Future[T], maxQueueTime: Duration = Duration.Inf)
(d: LimitDetector = limitDetection)
: Future[T] = this.synchronized {
val p = Promise[T]()
val startDeadline =
if (maxQueueTime.isFinite)
Some(LocalDateTime.now().plusSeconds(maxQueueTime.toSeconds))
else
None
requestQueue.offerLast(RequestQueueItem(f, p, d, startDeadline))
tryRequest()
p.future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment