XHR timeouts use same abstraction as scripts timers. (fixes #3396)

This commit is contained in:
benshu 2015-10-23 11:54:45 +02:00
parent 13226f8472
commit d27a3244f2
6 changed files with 139 additions and 49 deletions

View file

@ -22,8 +22,9 @@ use msg::constellation_msg::{ConstellationChan, PipelineId, WorkerId};
use net_traits::ResourceTask;
use profile_traits::mem;
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptTask};
use script_traits::TimerEventRequest;
use script_traits::{MsDuration, TimerEventRequest};
use std::sync::mpsc::Sender;
use timers::{ScheduledCallback, TimerHandle};
use url::Url;
use util::mem::HeapSizeOf;
@ -197,6 +198,23 @@ impl<'a> GlobalRef<'a> {
}
}
/// Schedule the given `callback` to be invoked after at least `duration` milliseconds have
/// passed.
pub fn schedule_callback(&self, callback: Box<ScheduledCallback>, duration: MsDuration) -> TimerHandle {
match *self {
GlobalRef::Window(window) => window.schedule_callback(callback, duration),
GlobalRef::Worker(worker) => worker.schedule_callback(callback, duration),
}
}
/// Unschedule a previously-scheduled callback.
pub fn unschedule_callback(&self, handle: TimerHandle) {
match *self {
GlobalRef::Window(window) => window.unschedule_callback(handle),
GlobalRef::Worker(worker) => worker.unschedule_callback(handle),
}
}
/// Returns the receiver's reflector.
pub fn reflector(&self) -> &Reflector {
match *self {