Fetch cancellation: Send cancellation message whenever XHR needs to abort a fetch

This commit is contained in:
Manish Goregaokar 2017-11-17 13:25:50 -08:00
parent 87e4c15280
commit 27457e4d84

View file

@ -1023,6 +1023,12 @@ impl XMLHttpRequest {
} }
fn terminate_ongoing_fetch(&self) { fn terminate_ongoing_fetch(&self) {
if let Some(ref cancel_chan) = *self.cancellation_chan.borrow() {
// The receiver will be destroyed if the request has already completed;
// so we throw away the error. Cancellation is a courtesy call,
// we don't actually care if the other side heard.
let _ = cancel_chan.send(());
}
let GenerationId(prev_id) = self.generation_id.get(); let GenerationId(prev_id) = self.generation_id.get();
self.generation_id.set(GenerationId(prev_id + 1)); self.generation_id.set(GenerationId(prev_id + 1));
self.response_status.set(Ok(())); self.response_status.set(Ok(()));