mirror of
https://github.com/servo/servo.git
synced 2025-06-27 18:43:40 +01:00
DevTools: Improve resource_available
to handle multiple connections (#36933)
This patch improves the `resource_available` trait to handle multiple connections. In this patch we also remove the redundant `resource_available` from worker actor Testing: Existing tests in DevTools already tests for this. We do not need to add new test Fixes: part of #36027 Signed-off-by: atbrakhi <atbrakhi@igalia.com> Co-authored-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
parent
e5347eceac
commit
2aaf9695df
6 changed files with 51 additions and 62 deletions
|
@ -2,13 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::net::TcpStream;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::StreamId;
|
||||
use crate::protocol::JsonPacketStream;
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -22,21 +19,27 @@ pub(crate) struct ResourceAvailableReply<T: Serialize> {
|
|||
pub(crate) trait ResourceAvailable {
|
||||
fn actor_name(&self) -> String;
|
||||
|
||||
fn get_streams(&self) -> &RefCell<HashMap<StreamId, TcpStream>>;
|
||||
|
||||
fn resource_available<T: Serialize>(&self, resource: T, resource_type: String) {
|
||||
self.resources_available(vec![resource], resource_type);
|
||||
fn resource_available<T: Serialize>(
|
||||
&self,
|
||||
resource: T,
|
||||
resource_type: String,
|
||||
stream: &mut TcpStream,
|
||||
) {
|
||||
self.resources_available(vec![resource], resource_type, stream);
|
||||
}
|
||||
|
||||
fn resources_available<T: Serialize>(&self, resources: Vec<T>, resource_type: String) {
|
||||
fn resources_available<T: Serialize>(
|
||||
&self,
|
||||
resources: Vec<T>,
|
||||
resource_type: String,
|
||||
stream: &mut TcpStream,
|
||||
) {
|
||||
let msg = ResourceAvailableReply::<T> {
|
||||
from: self.actor_name(),
|
||||
type_: "resources-available-array".into(),
|
||||
array: vec![(resource_type, resources)],
|
||||
};
|
||||
|
||||
for stream in self.get_streams().borrow_mut().values_mut() {
|
||||
let _ = stream.write_json_packet(&msg);
|
||||
}
|
||||
let _ = stream.write_json_packet(&msg);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue