Adding in timestamps_absolute_difference

This commit is contained in:
Pauan 2018-11-24 11:08:59 -10:00
parent 1c204b2d13
commit de331b2c2e
2 changed files with 18 additions and 3 deletions

2
Cargo.lock generated
View File

@ -10,7 +10,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dominator"
version = "0.3.2"
version = "0.3.4"
dependencies = [
"discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-channel-preview 0.3.0-alpha.9 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -523,7 +523,7 @@ impl MutableTimestamps<F> where F: FnMut(f64) {
}*/
pub fn timestamps_difference() -> impl Signal<Item = Option<f64>> {
pub fn timestamps_absolute_difference() -> impl Signal<Item = Option<f64>> {
let mut starting_time = None;
timestamps().map(move |current_time| {
@ -535,12 +535,27 @@ pub fn timestamps_difference() -> impl Signal<Item = Option<f64>> {
}
pub fn timestamps_difference() -> impl Signal<Item = Option<f64>> {
let mut previous_time = None;
timestamps().map(move |current_time| {
let diff = current_time.map(|current_time| {
previous_time.map(|previous_time| current_time - previous_time).unwrap_or(0.0)
});
previous_time = current_time;
diff
})
}
pub struct OnTimestampDiff(DiscardOnDrop<CancelableFutureHandle>);
impl OnTimestampDiff {
pub fn new<F>(mut callback: F) -> Self where F: FnMut(f64) + 'static {
OnTimestampDiff(spawn_future(
timestamps_difference()
timestamps_absolute_difference()
.for_each(move |diff| {
if let Some(diff) = diff {
callback(diff);