Created
December 14, 2015 09:56
-
-
Save dns2utf8/d1db02cd530bd809371b to your computer and use it in GitHub Desktop.
This file contains 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
use std::time::Duration; | |
struct CachedValue<T, U> { | |
last : Duration, | |
value : T, | |
updateFunction : U, | |
} | |
impl <T, U> CachedValue<T,U> { | |
pub fn new(base :T, updateFunction :U, duration :Duration) -> CachedValue<T,U> { | |
CachedValue { | |
value: base, | |
last: duration, | |
updateFunction: updateFunction, | |
} | |
} | |
pub fn value(&self) -> T { | |
// if timeout Reached | |
// updateFunction() | |
self.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment