diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index aad61971fd7..90d30500d7c 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -46,6 +46,7 @@ use hyper::method::Method; use hyper::mime::{Attr, Mime}; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; +use ipc_channel::router::ROUTER; use msg::constellation_msg::{PipelineId, ReferrerPolicy}; use request::{Request, RequestInit}; use response::{HttpsState, Response}; @@ -482,6 +483,19 @@ pub fn load_async(context: LoadContext, core_resource_thread.send(CoreResourceMsg::Load(load_data, consumer, None)).unwrap(); } +/// Instruct the resource thread to make a new request. +pub fn fetch_async(request: RequestInit, + core_resource_thread: &CoreResourceThread, + f: F) + where F: Fn(FetchResponseMsg) + Send + 'static +{ + let (action_sender, action_receiver) = ipc::channel().unwrap(); + ROUTER.add_route(action_receiver.to_opaque(), box move |message| { + f(message.to().unwrap()); + }); + core_resource_thread.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap(); +} + /// Message sent in response to `Load`. Contains metadata, and a port /// for receiving the data. ///