diff options
Diffstat (limited to 'components/script/dom/bindings/global.rs')
-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 { |