Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Simplify return
Browse files Browse the repository at this point in the history
  • Loading branch information
madsodgaard committed Apr 13, 2021
1 parent 3e78119 commit d0a8273
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Sources/Gatekeeper/Gatekeeper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ public struct Gatekeeper {
else: error
)
.map(updateEntry)
.flatMap { entry -> EventLoopFuture<Entry> in
.flatMap { entry in
// The amount of time the entry has existed.
let entryLifetime = Int(Date().timeIntervalSince1970 - entry.createdAt.timeIntervalSince1970)
// Remaining time until the entry expires. The entry would be expired by cache if it was negative.
let timeRemaining = Int(config.refreshInterval) - entryLifetime

return cache
.set(cacheKey, to: entry, expiresIn: .seconds(timeRemaining))
.transform(to: entry)
return cache.set(cacheKey, to: entry, expiresIn: .seconds(timeRemaining))
}
}
.transform(to: ())
}

private func updateEntry(_ entry: Entry) -> Entry {
Expand Down

0 comments on commit d0a8273

Please sign in to comment.