Last active
June 22, 2018 00:41
-
-
Save JohnMurray/f31eeff6c379fac19a18003c03371de1 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 cleanupRequests() { | |
val now = LocalDateTime.now() | |
if (now.isAfter(nextCleanupTime)) { | |
requestQueue.removeIf((req) => { | |
val expired = req.startDeadline.exists(now.isAfter) | |
if (expired) { | |
req.p.complete(Failure(new TimeoutException)) | |
} | |
expired | |
}) | |
nextCleanupTime = now.plusSeconds(cleanupTimeFrame.toSeconds) | |
} | |
} | |
private def tryRequest(): Unit = this.synchronized { | |
cleanupRequests() | |
// other code ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment