JavaScript Simulate Promise with setTimeOut

Looking for how to use setTimeOut With Promise, Here is a good example of how to do that. setTimeOut are are very good especially when you want to have a little delay before you run the next command or function.

How to use promise on JavaScript.

Top 5 UI Designs

The first method we can use is  to use a setTimeOut Directly inside our Promise Chain

new Promise((resolve, reject) => {
 setTimeOut(resolve, 2000)
}).then(() =>{
 // Perform some operation.

The second way of doing this is to create a delay() function

function delay(t, v) {
   return new Promise(function(resolve) { 
       setTimeout(resolve.bind(null, v), t)
delay(1000).then(function() {
        return value;

You can also add a delay method to the Promise object and then directly use a .delay(x) method on your promises like this:

function delay(time, value) {
   return new Promise(function(resolve) { 
       setTimeout(resolve.bind(null, value), time)
Promise.prototype.delay = function(time) {
    return this.then(function(value) {
        return delay(time, value);
Promise.resolve(\"hello\").delay(500).then(function(value) {

Or you can use the BlueBird Libary, It already has the delay function on it.