mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Implement fetch_async in net_traits.
This commit is contained in:
parent
44c80d5b18
commit
a79c06d9c0
1 changed files with 14 additions and 0 deletions
|
@ -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.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue