diff options
author | benshu <benshu@benshu.de> | 2015-10-23 11:54:45 +0200 |
---|---|---|
committer | benshu <benshu@benshu.de> | 2015-11-11 00:52:34 +0100 |
commit | d27a3244f2e77f52c62a90bf308d07e069f8390c (patch) | |
tree | c1d3da39bd4b1df3541b84cdb553aa18e5d0980b /components/script/dom/bindings | |
parent | 13226f847234cd0130820338d5a272277780d278 (diff) | |
download | servo-d27a3244f2e77f52c62a90bf308d07e069f8390c.tar.gz servo-d27a3244f2e77f52c62a90bf308d07e069f8390c.zip |
XHR timeouts use same abstraction as scripts timers. (fixes #3396)
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/global.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index d89c1c21f32..f8f24d862df 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -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 { |