Shutting down a Mojo::IOLoop recurring event connected to a Mojo websocket

I'm playing around with Mojolicious and websockets. I want to send the output of multiple external commands on the server to the webpage. I have no problems with connecting and receiving messages, but I also want to send a message back to the server to stop an external command while letting the others keep sending messages back to the client. I also want to stop checking the external command once it exits.

The external command is simply a one-liner that spits out an integer every few seconds. I have two websockets that display the numbers in separate

div

s. Clicking either of the stop buttons sends the message, but that's where I need to figure out how to shut down that websocket (and only that websocket) and shut down the external command.

When I connect the websocket, I run the external command and set up a

Mojo::IOLoop->recurring

to check if there's output.

When I want to stop, I figure that I should call

Mojo::IOLoop->remove($id)

, but that doesn't seem to completely remove it and I get error messages like