• await 暂停 等待 暂停的是什么


    体验异步的终极解决方案-ES7的Async/Await

    var sleep = function (time) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                resolve();
            }, time);
        })
    };
    
    var start = async function () {
        // 在这里使用起来就像同步代码那样直观
        console.log('start');
        await sleep(3000);
        console.log('end');
    };
    
    start();


    体验异步的终极解决方案-ES7的Async/Await - CNode技术社区 https://cnodejs.org/topic/5640b80d3a6aa72c5e0030b6




    对比


    var sleep = function (time) {
    return new Promise(function (resolve, reject) {
    setTimeout(function () {
    resolve();
    }, time);
    })
    };

    var start = async function () {
    // 在这里使用起来就像同步代码那样直观
    console.log('start');
    await sleep(3000);
    console.log('end');
    };

    start();
    console.log('AFTER start();');

    function resolveAfter2Seconds() {
    return new Promise(resolve => {
    setTimeout(() => {
    resolve('resolved');
    }, 10000);
    });
    }

    async function asyncCall() {
    console.log('calling');
    var result = await resolveAfter2Seconds();
    console.log(result);
    // expected output: 'resolved'
    }

    asyncCall();




  • 相关阅读:
    mysql -- 备忘
    Linux基础命令---压缩与打包
    nginx rewrite
    重启php-fpm
    Mysql:输出到文件
    IOS 自定义Layer(图层)
    IOS CALayer基本使用 (图层)
    IOS 拖拽事件(手势识别)
    IOS 旋转+缩放(手势识别)
    IOS 长按+轻扫(手势识别)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9563571.html
Copyright © 2020-2023  润新知