async await的使用

var sleep = function (time) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {        //此处执行异步操作
            resolve('ok');

        }, time);

    });
};

var start = async function () {
    try{
        console.log('start');
        var result = await sleep(1000);
        console.log(result);
        console.log('end');
    }catch(err){
        console.log(err);
    }
    
};

start();

 

posted @ 2017-05-12 16:26  webbky  阅读(120)  评论(0编辑  收藏  举报