Repository: bevyengine/bevy
File: crates/bevy_asset/src/processor/mod.rs (Rust)

Code before:
        let log = log.as_mut().unwrap();
        log.begin_processing(path)
            .await
            .map_err(|error| WriteLogError {
                log_entry: LogEntry::BeginProcessing(path.clone_owned()),
                error,
            })
            .unwrap();
    }

    /// Logs the end of an asset being successfully processed. See [`AssetProcessor::log_begin_processing`].
    async fn log_end_processing(&self, path: &AssetPath<'_>) {
        let mut log = self.data.log.write().await;
        let log = log.as_mut().unwrap();
        log.end_processing(path)
            .await
            .map_err(|error| WriteLogError {
                log_entry: LogEntry::EndProcessing(path.clone_owned()),
                error,
            })
            .unwrap();
    }

    /// Starts the processor in a background thread.
    pub fn start(_processor: Res<Self>) {
        let processor = _processor.clone();
        IoTaskPool::get()
            .spawn(async move {
                let start_time = std::time::Instant::now();
                debug!("Processing Assets");

                processor.initialize().await.unwrap();

                let (task_event_sender, task_event_receiver) = async_channel::unbounded();
                processor
                    .queue_initial_processing_tasks(&task_event_sender)
                    .await;

                // Once all the tasks are queued for the initial processing, start actually
                // executing the tasks.
                {
                    let processor = processor.clone();
                    let task_event_sender = task_event_sender.clone();
                    let task_event_receiver = task_event_receiver.clone();
                    IoTaskPool::get()
                        .spawn(async move {
                            processor
                                .execute_processing_tasks(&task_event_sender, &task_event_receiver)
                                .await;
                        })
                        .detach();

Review comment (suggestion):
Not from this PR but I think it's better style to shadow `processor` here instead of using an underscore for a variable which is in use.

Code after:
        let mut log = self.data.log.write().await;
        let log = log.as_mut().unwrap();
        log.begin_processing(path)
            .await
            .map_err(|error| WriteLogError {
                log_entry: LogEntry::BeginProcessing(path.clone_owned()),
                error,
            })
            .unwrap();
    }

    /// Logs the end of an asset being successfully processed. See [`AssetProcessor::log_begin_processing`].
    async fn log_end_processing(&self, path: &AssetPath<'_>) {
        let mut log = self.data.log.write().await;
        let log = log.as_mut().unwrap();
        log.end_processing(path)
            .await
            .map_err(|error| WriteLogError {
                log_entry: LogEntry::EndProcessing(path.clone_owned()),
                error,
            })
            .unwrap();
    }

    /// Starts the processor in a background thread.
    pub fn start(processor: Res<Self>) {
        let processor = processor.clone();
        IoTaskPool::get()
            .spawn(async move {
                let start_time = std::time::Instant::now();
                debug!("Processing Assets");

                processor.initialize().await.unwrap();

                let (new_task_sender, new_task_receiver) = async_channel::unbounded();
                processor
                    .queue_initial_processing_tasks(&new_task_sender)
                    .await;

                // Once all the tasks are queued for the initial processing, start actually
                // executing the tasks.
                {
                    let processor = processor.clone();
                    let new_task_sender = new_task_sender.clone();
                    IoTaskPool::get()
                        .spawn(async move {
                            processor
                                .execute_processing_tasks(new_task_sender, new_task_receiver)
                                .await;
                        })
                        .detach();