'VSCode extension: How can I remove the error message automatically after x amount of time?

I'm building a VSCode extension and I have an error message which pops up if my condition turns out true. I want the error message to disappear after for example 5 seconds.

I tried the following approach:

let count = 0

if (condition) {
    setInterval(() => {
          count++
    }, 1000);
    while (count <= 5) {    
        vscode.window.showErrorMessage(`Error!`);
    }
}

But that didn't work..., How can I achieve this?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source