mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
impl timer-task-source, dedicated time-out mechanism for service-worker
This commit is contained in:
parent
d553158e95
commit
50a7111eb6
13 changed files with 241 additions and 204 deletions
|
@ -34,8 +34,12 @@ pub struct OneshotTimerHandle(i32);
|
|||
pub struct OneshotTimers {
|
||||
js_timers: JsTimers,
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
timer_event_chan: IpcSender<TimerEvent>,
|
||||
/// The sender, to be cloned for each timer,
|
||||
/// on which the timer scheduler in the constellation can send an event
|
||||
/// when the timer is due.
|
||||
timer_event_chan: DomRefCell<Option<IpcSender<TimerEvent>>>,
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
/// The sender to the timer scheduler in the constellation.
|
||||
scheduler_chan: IpcSender<TimerSchedulerMsg>,
|
||||
next_timer_handle: Cell<OneshotTimerHandle>,
|
||||
timers: DomRefCell<Vec<OneshotTimer>>,
|
||||
|
@ -109,13 +113,10 @@ impl PartialEq for OneshotTimer {
|
|||
}
|
||||
|
||||
impl OneshotTimers {
|
||||
pub fn new(
|
||||
timer_event_chan: IpcSender<TimerEvent>,
|
||||
scheduler_chan: IpcSender<TimerSchedulerMsg>,
|
||||
) -> OneshotTimers {
|
||||
pub fn new(scheduler_chan: IpcSender<TimerSchedulerMsg>) -> OneshotTimers {
|
||||
OneshotTimers {
|
||||
js_timers: JsTimers::new(),
|
||||
timer_event_chan: timer_event_chan,
|
||||
timer_event_chan: DomRefCell::new(None),
|
||||
scheduler_chan: scheduler_chan,
|
||||
next_timer_handle: Cell::new(OneshotTimerHandle(1)),
|
||||
timers: DomRefCell::new(Vec::new()),
|
||||
|
@ -125,6 +126,12 @@ impl OneshotTimers {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn setup_scheduling(&self, timer_event_chan: IpcSender<TimerEvent>) {
|
||||
let mut chan = self.timer_event_chan.borrow_mut();
|
||||
assert!(chan.is_none());
|
||||
*chan = Some(timer_event_chan);
|
||||
}
|
||||
|
||||
pub fn schedule_callback(
|
||||
&self,
|
||||
callback: OneshotTimerCallback,
|
||||
|
@ -279,7 +286,10 @@ impl OneshotTimers {
|
|||
.saturating_sub(precise_time_ms().get()),
|
||||
);
|
||||
let request = TimerEventRequest(
|
||||
self.timer_event_chan.clone(),
|
||||
self.timer_event_chan
|
||||
.borrow()
|
||||
.clone()
|
||||
.expect("Timer event chan not setup to schedule timers."),
|
||||
timer.source,
|
||||
expected_event_id,
|
||||
delay,
|
||||
|
@ -331,6 +341,7 @@ pub struct JsTimerHandle(i32);
|
|||
#[derive(DenyPublicFields, JSTraceable, MallocSizeOf)]
|
||||
pub struct JsTimers {
|
||||
next_timer_handle: Cell<JsTimerHandle>,
|
||||
/// https://html.spec.whatwg.org/multipage/#list-of-active-timers
|
||||
active_timers: DomRefCell<HashMap<JsTimerHandle, JsTimerEntry>>,
|
||||
/// The nesting level of the currently executing timer task or 0.
|
||||
nesting_level: Cell<u32>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue