The issue is with your 4th parameter that you are passing to $messages.registerWarning...
$messages.registerWarning("myTitle", "myDesc", null, true); // true is for isModal
This is essentially making your warning as a modal that requires user interaction, and you wont be able to the doArchive
and dispose
on it until after the user has clicked the button. Setting this option to false will allow it to work just like a notification where the message will appear at the top right of the screen, and will be disposable without having the user to click anything.
$messages.registerWarning("title","desc",null, false)
$messages.getActiveMessages().forEach(function (message) {
message.doArchive();
message.dispose();
});
Hope that helps!