Script ending without sendText()

I’m new to the whole scripting thing, and I’m not understanding something. After websocket:connect() the script ends if nothing else blocks it, but if I add websocket:sendText() in the onreceive function when messageType == WebSocketMessageType.OPEN, then the script doesn’t end. Even if I use a dialog to make sure the connection finishes, if I then close the dialog window, the websocket connection closes, but if I have websocket:sendText() in the onreceive function, it keeps running even after closing the dialog window. It works for me, since I don’t want the dialog window, but why is that one sendText() keeping the script running?