Q:

Running a function after a certain period of time without holding up the execution thread

I've been working on a Discord bot using Discord.js and I've run into a frustrating limitation of Javascript that I'm trying to find a workaround for. 
Essentially, I come to a point in my code where I want to wait a set period of time. 
Currently, I have this implemented in my code as
while (new Date().getTime() < targetTime)
{
    //Waiting
}

The problem is that other aspects of my code can not function while this while loop is in action. 
For example, I have an event listener for anytime a user sends a message in Discord, but the listener does not work while the while loop is executing. 
client.on('message', async message => {
     //stuff happens here
}

Any recommendations on how to get this to work? 

A:

That is expected behavior, the main thread is "busy" getting a current date on every thick. 
So he cannot do anything else, because js is single-threaded. 
You can use node-schedule npm package which implements a better algorithm for observing the current date. 
const date = new Date(2020, 1, 22, 12, 0, 0);

schedule.scheduleJob(date, function(){
  console.log('job is running');
});

