Repository: servo/servo
File: components/script/dom/gamepad/gamepadhapticactuator.rs (Rust)

Code before:
        self.sequence_id.set(self.sequence_id.get().wrapping_add(1));

        if let Some(promise) = self.playing_effect_promise.borrow_mut().take() {
            let trusted_promise = TrustedPromise::new(promise);
            self.global().task_manager().gamepad_task_source().queue(
                task!(preempt_promise: move || {
                    let promise = trusted_promise.root();
                    let message = DOMString::from("preempted");
                    promise.resolve_native(&message, CanGc::note());
                }),
            );
        }

        *self.playing_effect_promise.borrow_mut() = Some(promise.clone());

        self.reset_sequence_id.set(self.sequence_id.get());

        let context = Trusted::new(self);
        let listener = HapticEffectListener {
            task_source: self.global().task_manager().gamepad_task_source().into(),
            context,
        };

        let callback = GenericCallback::new(move |message| match message {
            Ok(msg) => listener.handle_stopped(msg),
            Err(err) => warn!("Error receiving a GamepadMsg: {:?}", err),
        })
        .expect("Could not create callback");

        let event = EmbedderMsg::StopGamepadHapticEffect(
            document.webview_id(),
            self.gamepad_index as usize,
            callback,
        );
        self.global().as_window().send_to_embedder(event);

        self.playing_effect_promise.borrow().clone().unwrap()
    }
}

impl GamepadHapticActuator {
    /// <https://www.w3.org/TR/gamepad/#dom-gamepadhapticactuator-playeffect>
    /// We are in the task queued by the "in-parallel" steps.
    pub(crate) fn handle_haptic_effect_completed(
        &self,
        completed_successfully: bool,
        can_gc: CanGc,
    ) {
        if self.effect_sequence_id.get() != self.sequence_id.get() || !completed_successfully {
            return;
        }

Review comment (suggestion):
```suggestion
            Err(error) => warn!("Error receiving a GamepadMsg: {error:?}"),
```

Code after:
        self.sequence_id.set(self.sequence_id.get().wrapping_add(1));

        if let Some(promise) = self.playing_effect_promise.borrow_mut().take() {
            let trusted_promise = TrustedPromise::new(promise);
            self.global().task_manager().gamepad_task_source().queue(
                task!(preempt_promise: move || {
                    let promise = trusted_promise.root();
                    let message = DOMString::from("preempted");
                    promise.resolve_native(&message, CanGc::note());
                }),
            );
        }

        *self.playing_effect_promise.borrow_mut() = Some(promise.clone());

        self.reset_sequence_id.set(self.sequence_id.get());

        let context = Trusted::new(self);
        let listener = HapticEffectListener {
            task_source: self.global().task_manager().gamepad_task_source().into(),
            context,
        };

        let callback = GenericCallback::new(move |message| match message {
            Ok(success) => listener.handle_stopped(success),
            Err(error) => warn!("Error receiving a GamepadMsg: {error:?}"),
        })
        .expect("Could not create callback");

        let event = EmbedderMsg::StopGamepadHapticEffect(
            document.webview_id(),
            self.gamepad_index as usize,
            callback,
        );
        self.global().as_window().send_to_embedder(event);

        self.playing_effect_promise.borrow().clone().unwrap()
    }
}

impl GamepadHapticActuator {
    /// <https://www.w3.org/TR/gamepad/#dom-gamepadhapticactuator-playeffect>
    /// We are in the task queued by the "in-parallel" steps.
    pub(crate) fn handle_haptic_effect_completed(
        &self,
        completed_successfully: bool,
        can_gc: CanGc,
    ) {
        if self.effect_sequence_id.get() != self.sequence_id.get() || !completed_successfully {
            return;
        }