码迷,mamicode.com
首页 > 其他好文 > 详细

async await的使用

时间:2017-05-12 17:31:04      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:timeout   ret   pre   nbsp   res   span   art   await   start   

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();

 

async await的使用

标签:timeout   ret   pre   nbsp   res   span   art   await   start   

原文地址:http://www.cnblogs.com/wanghaonull/p/6846096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!