diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-03-11 10:44:59 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-05-20 14:22:09 -0400 |
commit | 8082df7d0da97f1951ae125956b962b92c98e69f (patch) | |
tree | 86131e200a39a6f85afcfff7fa8f6f904e94cc0b /components/script/document_loader.rs | |
parent | e52197d1261055527a838f74b353a1124d6b077a (diff) | |
download | servo-8082df7d0da97f1951ae125956b962b92c98e69f.tar.gz servo-8082df7d0da97f1951ae125956b962b92c98e69f.zip |
Make external script sources load asynchronously, yet still block further parsing. Hook up document loading to async networking events.
Diffstat (limited to 'components/script/document_loader.rs')
-rw-r--r-- | components/script/document_loader.rs | 13 |
1 files changed, 6 insertions, 7 deletions
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<LoadResponse> { + pub fn load_async(&mut self, load: LoadType, listener: Box<AsyncResponseTarget + Send>) { 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() { |