Fix embassy-time wasm build and fix a bug in wasm time driver
This commit is contained in:
parent
e3cf4255c6
commit
516f4ce946
@ -81,26 +81,32 @@ impl Driver for TimeDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) -> bool {
|
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
|
||||||
self.init();
|
self.init();
|
||||||
let mut alarms = unsafe { self.alarms.as_ref() }.lock().unwrap();
|
let mut alarms = unsafe { self.alarms.as_ref() }.lock().unwrap();
|
||||||
let alarm = &mut alarms[alarm.id() as usize];
|
let alarm = &mut alarms[alarm.id() as usize];
|
||||||
alarm.closure.replace(Closure::new(move || {
|
alarm.closure.replace(Closure::new(move || {
|
||||||
callback(ctx);
|
callback(ctx);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) {
|
fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool {
|
||||||
self.init();
|
self.init();
|
||||||
let mut alarms = unsafe { self.alarms.as_ref() }.lock().unwrap();
|
let mut alarms = unsafe { self.alarms.as_ref() }.lock().unwrap();
|
||||||
let alarm = &mut alarms[alarm.id() as usize];
|
let alarm = &mut alarms[alarm.id() as usize];
|
||||||
let timeout = (timestamp - self.now()) as u32;
|
|
||||||
if let Some(token) = alarm.token {
|
if let Some(token) = alarm.token {
|
||||||
clearTimeout(token);
|
clearTimeout(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let now = self.now();
|
||||||
|
if timestamp <= now {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
let timeout = (timestamp - now) as u32;
|
||||||
alarm.token = Some(setTimeout(alarm.closure.as_ref().unwrap(), timeout / 1000));
|
alarm.token = Some(setTimeout(alarm.closure.as_ref().unwrap(), timeout / 1000));
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user