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
- Swift package manager
- Carthage
- Manual copying of the one file
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.
The protocol exposed in this micro library, it expects two pieces of data
expirationMarginInterval: TimeInterval
an interval preceeding the expiry used to send a message of impending expiry
syncronous access to whether the object has expired
syncronous access to whether the object has expired or is about to expire, based on subtracting the expirationMarginInterval
from the expiresAt
date
an observable that will fire as soon as the current date is greater than expiresAt - expirationMarginInterval
.