Skip to content

Commit 4279f2d

Browse files
fix time delay calc
1 parent 7685a5f commit 4279f2d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn output_send(
162162
) -> Result<(), String> {
163163
let timestamp = timestamp
164164
.map(|s| {
165-
s.parse::<u64>()
165+
s.parse::<u128>()
166166
.map_err(|e| format!("Failed to parse timestamp: {e}"))
167167
})
168168
.transpose()?;
@@ -178,15 +178,13 @@ fn output_send(
178178
drop(state);
179179
let tstate = (*tstate).clone();
180180
tauri::async_runtime::spawn(async move {
181-
let until = Instant::now()
182-
// We take `1ms` for processing overhead
183-
+ Duration::from_millis(timestamp - 1)
184-
.checked_sub(
185-
SystemTime::now()
186-
.duration_since(UNIX_EPOCH)
187-
.expect("SystemTime is before epoch"),
188-
)
189-
.unwrap_or(Duration::ZERO);
181+
let current_epoch = SystemTime::now()
182+
.duration_since(UNIX_EPOCH)
183+
.expect("SystemTime is before epoch")
184+
.as_millis();
185+
186+
let delay_ms = timestamp.saturating_sub(current_epoch);
187+
let until = Instant::now() + Duration::from_millis(delay_ms as u64);
190188
sleep_until(until.into()).await;
191189

192190
let mut state = tstate.lock().unwrap_or_else(PoisonError::into_inner);

0 commit comments

Comments
 (0)