promise-2.js

function getPromise() {
  const taskPromise = new Promise((resolve, reject) => {
    console.log("task started.");
    
    setTimeout(() => {
      console.log("done after 100ms.");
      resolve();
    }, 100);
  });
  
  return taskPromise;
}

const taskPromise = () => getPromise();

console.log("**Some other work before promise**");

// Now when taskPromise function is invoked, executor will be executed
taskPromise();