Implement fetch_async in net_traits.

This commit is contained in:
Ms2ger 2016-10-11 17:39:01 +02:00
parent 44c80d5b18
commit a79c06d9c0

View file

@ -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<F>(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.
///