Return to Snippet

Revision: 72338
at July 23, 2017 12:12 by sudhiakki


Initial Code
var milllisecond = 4000;
function wait(ms){
    console.log('started');
    // new promise
    return new Promise(function(resolve,reject){
        console.log(this);
        window.setTimeout(function(){
            // resolve inside the callback of settimeout
            resolve(ms); 
	    reject(ms);
        },ms);
    });
};

wait(milllisecond).then(finish);

function finish(a){
console.log(1+a)
};

Initial URL

                                

Initial Description
Warp settimeout function in promise

Initial Title
JS promise : Wrap settimeout in promise

Initial Tags

                                

Initial Language
JavaScript