mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Simplify AsyncResponseListener implementations.
This commit is contained in:
parent
c1aff0b678
commit
827f2b873c
3 changed files with 23 additions and 25 deletions
|
@ -23,7 +23,6 @@ use network_listener::{NetworkListener, PreInvoke};
|
|||
use script_task::ScriptChan;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use time::{self, Timespec, now};
|
||||
use unicase::UniCase;
|
||||
|
@ -106,7 +105,7 @@ impl CORSRequest {
|
|||
script_chan: Box<ScriptChan + Send>) {
|
||||
struct CORSContext {
|
||||
listener: Box<AsyncCORSResponseListener + Send>,
|
||||
response: RefCell<Option<CORSResponse>>,
|
||||
response: Option<CORSResponse>,
|
||||
}
|
||||
|
||||
// This is shoe-horning the CORSReponse stuff into the rest of the async network
|
||||
|
@ -119,7 +118,7 @@ impl CORSRequest {
|
|||
}
|
||||
|
||||
fn response_complete(&mut self, _status: Result<(), String>) {
|
||||
let response = self.response.borrow_mut().take().unwrap();
|
||||
let response = self.response.take().unwrap();
|
||||
self.listener.response_available(response);
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ impl CORSRequest {
|
|||
|
||||
let context = CORSContext {
|
||||
listener: listener,
|
||||
response: RefCell::new(None),
|
||||
response: None,
|
||||
};
|
||||
let listener = NetworkListener {
|
||||
context: Arc::new(Mutex::new(context)),
|
||||
|
@ -141,7 +140,7 @@ impl CORSRequest {
|
|||
let response = req.http_fetch();
|
||||
let mut context = listener.context.lock();
|
||||
let context = context.as_mut().unwrap();
|
||||
*context.response.borrow_mut() = Some(response);
|
||||
context.response = Some(response);
|
||||
listener.notify(ResponseAction::ResponseComplete(Ok(())));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue