From 8082df7d0da97f1951ae125956b962b92c98e69f Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 11 Mar 2015 10:44:59 -0400 Subject: Make external script sources load asynchronously, yet still block further parsing. Hook up document loading to async networking events. --- components/script/document_loader.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'components/script/document_loader.rs') diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 6b8dfcea801..14e107e9d02 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -7,13 +7,12 @@ use script_task::{ScriptMsg, ScriptChan}; use msg::constellation_msg::{PipelineId}; -use net_traits::{LoadResponse, Metadata, load_whole_resource, ResourceTask, PendingAsyncLoad}; +use net_traits::{Metadata, load_whole_resource, ResourceTask, PendingAsyncLoad}; +use net_traits::AsyncResponseTarget; use url::Url; -use std::sync::mpsc::Receiver; - #[jstraceable] -#[derive(PartialEq, Clone)] +#[derive(PartialEq, Clone, Debug)] pub enum LoadType { Image(Url), Script(Url), @@ -75,9 +74,9 @@ impl DocumentLoader { } /// Create and initiate a new network request. - pub fn load_async(&mut self, load: LoadType) -> Receiver { + pub fn load_async(&mut self, load: LoadType, listener: Box) { let pending = self.prepare_async_load(load); - pending.load() + pending.load_async(listener) } /// Create, initiate, and await the response for a new network request. @@ -91,7 +90,7 @@ impl DocumentLoader { /// Mark an in-progress network request complete. pub fn finish_load(&mut self, load: LoadType) { let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load); - self.blocking_loads.remove(idx.expect("unknown completed load")); + self.blocking_loads.remove(idx.expect(&format!("unknown completed load {:?}", load))); if let Some(NotifierData { ref script_chan, pipeline }) = self.notifier_data { if !self.is_blocked() { -- cgit v1.2.3