Repository: servo/servo
File: components/devtools/actors/console.rs (Rust)

Code before:
    from: String,
    #[serde(rename = "resultID")]
    result_id: String,
}

#[derive(Serialize)]
struct SetPreferencesReply {
    from: String,
    updated: Vec<String>,
}

pub(crate) enum Root {
    BrowsingContext(String),
    DedicatedWorker(String),
}

pub(crate) struct ConsoleActor {
    pub name: String,
    pub root: Root,
    pub cached_events: AtomicRefCell<HashMap<UniqueId, Vec<ConsoleResource>>>,
    /// Used to control whether to send resource array messages from
    /// `handle_console_resource`. It starts being false, and it only gets
    /// activated after the client requests `console-message` or `error-message`
    /// resources for the first time. Otherwise we would be sending messages
    /// before the client is ready to receive them.
    pub should_send_messages: AtomicBool,
}

impl ConsoleActor {
    fn script_chan(&self, registry: &ActorRegistry) -> GenericSender<DevtoolScriptControlMsg> {
        match &self.root {
            Root::BrowsingContext(browsing_context) => registry
                .find::<BrowsingContextActor>(browsing_context)
                .script_chan
                .clone(),
            Root::DedicatedWorker(worker) => {
                registry.find::<WorkerActor>(worker).script_chan.clone()
            },
        }
    }

    fn current_unique_id(&self, registry: &ActorRegistry) -> UniqueId {
        match &self.root {
            Root::BrowsingContext(browsing_context) => UniqueId::Pipeline(
                registry
                    .find::<BrowsingContextActor>(browsing_context)
                    .pipeline_id(),
            ),
            Root::DedicatedWorker(worker) => {
                UniqueId::Worker(registry.find::<WorkerActor>(worker).worker_id)
            },

Review comment (suggestion):
The documentation is really helpful here. If you'd like a suggestion for the name:

```suggestion
    pub client_ready_to_receive_messages: AtomicBool,
```

Code after:
    from: String,
    #[serde(rename = "resultID")]
    result_id: String,
}

#[derive(Serialize)]
struct SetPreferencesReply {
    from: String,
    updated: Vec<String>,
}

pub(crate) enum Root {
    BrowsingContext(String),
    DedicatedWorker(String),
}

pub(crate) struct ConsoleActor {
    pub name: String,
    pub root: Root,
    pub cached_events: AtomicRefCell<HashMap<UniqueId, Vec<ConsoleResource>>>,
    /// Used to control whether to send resource array messages from
    /// `handle_console_resource`. It starts being false, and it only gets
    /// activated after the client requests `console-message` or `error-message`
    /// resources for the first time. Otherwise we would be sending messages
    /// before the client is ready to receive them.
    pub client_ready_to_receive_messages: AtomicBool,
}

impl ConsoleActor {
    fn script_chan(&self, registry: &ActorRegistry) -> GenericSender<DevtoolScriptControlMsg> {
        match &self.root {
            Root::BrowsingContext(browsing_context) => registry
                .find::<BrowsingContextActor>(browsing_context)
                .script_chan
                .clone(),
            Root::DedicatedWorker(worker) => {
                registry.find::<WorkerActor>(worker).script_chan.clone()
            },
        }
    }

    fn current_unique_id(&self, registry: &ActorRegistry) -> UniqueId {
        match &self.root {
            Root::BrowsingContext(browsing_context) => UniqueId::Pipeline(
                registry
                    .find::<BrowsingContextActor>(browsing_context)
                    .pipeline_id(),
            ),
            Root::DedicatedWorker(worker) => {
                UniqueId::Worker(registry.find::<WorkerActor>(worker).worker_id)
            },