Created
January 29, 2018 14:16
-
-
Save JohnMurray/6c61a733513c0edd56c4cd2b7c73a2dc 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](limit: Long, timeFrame: FiniteDuration) { | |
// previous code ... | |
private def hasCapacity(): Boolean = { | |
val now = LocalDateTime.now() | |
if (now.isAfter(windowStopTime)) { | |
windowStopTime = now.plusSeconds(timeFrame.toSeconds) | |
requestCount = 0 | |
true | |
} else { | |
requestCount < limit | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment