A Swift µ-Library for modeling and reacting to values that expire
I wrote this while dealing with a number of expiring values (nonces from a hardware device, OAuth tokens, command tokens to send to hardware) during my time at Proxy.
It's a one-file dependency that exposes an Expirable
protocol. Once implemented by a object that models some data that becomes stale at some point in the future, you get a number of convienient ways to deal with and react to said data expiring
The package is available through
You can check out the Example.playground to see an example of the library in use. Make sure you carthage bootstrap
and build the Expirable framework, the playground can't run without them.
Expirable
The protocol exposed in this micro library, it expects two pieces of data
expiresAt: Date
the date at which the data expiresexpirationMarginInterval: TimeInterval
an interval preceeding the expiry used to send a message of impending expiryisValid: Bool
syncronous access to whether the object has expired
isExpiredOrExpiringSoon: Bool
syncronous access to whether the object has expired or is about to expire, based on subtracting the expirationMarginInterval
from the expiresAt
date
expiresSoon: Observable<Void>
an observable that will fire as soon as the current date is greater than expiresAt - expirationMarginInterval
.
link |
Stars: 10 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics