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

Code before:
                            }
                        },
                        "source" => {
                            let thread_actor = registry.find::<ThreadActor>(&target.thread);
                            target.resources_array(
                                thread_actor.source_manager.source_forms(registry),
                                resource.into(),
                                ResourceArrayType::Available,
                                &mut request,
                            );

                            for worker_name in &*root.workers.borrow() {
                                let worker = registry.find::<WorkerActor>(worker_name);
                                let thread = registry.find::<ThreadActor>(&worker.thread);

                                worker.resources_array(
                                    thread.source_manager.source_forms(registry),
                                    resource.into(),
                                    ResourceArrayType::Available,
                                    &mut request,
                                );
                            }
                        },
                        "console-message" | "error-message" => {
                            let console = registry.find::<ConsoleActor>(&target.console);
                            console.should_send_messages.store(true, Ordering::Relaxed);
                            target.resources_array(
                                console.get_cached_messages(registry, resource),
                                resource.into(),
                                ResourceArrayType::Available,
                                &mut request,
                            );

                            for worker_name in &*root.workers.borrow() {
                                let worker = registry.find::<WorkerActor>(worker_name);
                                let console = registry.find::<ConsoleActor>(&worker.console);

                                worker.resources_array(
                                    console.get_cached_messages(registry, resource),
                                    resource.into(),
                                    ResourceArrayType::Available,
                                    &mut request,
                                );
                            }
                        },
                        "network-event" => {},
                        _ => warn!("resource {} not handled yet", resource),
                    }
                }
                let msg = EmptyReplyMsg { from: self.name() };
                request.reply_final(&msg)?

Review comment (suggestion):
I think you can make this code a little bit more self-documenting by making `should_send_messages`/ `client_ready_to_receive_messages` private and have it set to true by a method called `fn received_first_message_from_client(&self)`. That way your code reflects the rustdoc.

Code after:
                        },
                        "source" => {
                            let thread_actor = registry.find::<ThreadActor>(&target.thread);
                            target.resources_array(
                                thread_actor.source_manager.source_forms(registry),
                                resource.into(),
                                ResourceArrayType::Available,
                                &mut request,
                            );

                            for worker_name in &*root.workers.borrow() {
                                let worker = registry.find::<WorkerActor>(worker_name);
                                let thread = registry.find::<ThreadActor>(&worker.thread);

                                worker.resources_array(
                                    thread.source_manager.source_forms(registry),
                                    resource.into(),
                                    ResourceArrayType::Available,
                                    &mut request,
                                );
                            }
                        },
                        "console-message" | "error-message" => {
                            let console = registry.find::<ConsoleActor>(&target.console);
                            console.received_first_message_from_client();
                            target.resources_array(
                                console.get_cached_messages(registry, resource),
                                resource.into(),
                                ResourceArrayType::Available,
                                &mut request,
                            );

                            for worker_name in &*root.workers.borrow() {
                                let worker = registry.find::<WorkerActor>(worker_name);
                                let console = registry.find::<ConsoleActor>(&worker.console);

                                worker.resources_array(
                                    console.get_cached_messages(registry, resource),
                                    resource.into(),
                                    ResourceArrayType::Available,
                                    &mut request,
                                );
                            }
                        },
                        "network-event" => {},
                        _ => warn!("resource {} not handled yet", resource),
                    }
                }
                let msg = EmptyReplyMsg { from: self.name() };
                request.reply_final(&msg)?
            },