Last active
June 21, 2018 23:13
-
-
Save JohnMurray/205f46ce35e514dadc5559aa02b6d1f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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