首页 > 其他 > 详细

promise async await

时间:2020-02-05 16:54:16      阅读:61      评论:0      收藏:0      [点我收藏+]
Promise
        // function fun(){
        //     return new Promise((res,rej)=>{
        //           res(1);
        //           rej(3)
        //     })
        // }
        //  fun().then((a)=>{
        //      console.log(a)
        //  }).catch((b)=>{
        //      console.log(b)
        //  })
        //   async和await  
        //    function 摇色子(){
        //        let a=parseInt(Math.random()*6+1)
        //        return new Promise((res)=>{
        //           setTimeout(()=>{
        //               res(a)
        //           },3000)
        //        })
        //    }  
        //    async function test(){
        //        let n=await 摇色子()
        //        console.log(n)
        //    } 
        //    test() 

        // function 摇色子(猜测) {
        //     return new Promise((res, rej) => {
        //         let a = parseInt(Math.random() * 6 + 1)
        //         if (a > 3) {
        //             if (猜测 === ‘大‘) {
        //                 res(a)
        //             } else {
        //                 rej(a)
        //             }
        //         } else {
        //             if (猜测 === ‘大‘) {
        //                 rej(a)
        //             } else {
        //                 res(a)
        //             }
        //         }
        //         setTimeout(() => {
        //             res(a)
        //         }, 300)
        //     })
        // }
        // async function test() {
        //     try {
        //         let n = await 摇色子(‘大‘)
        //         console.log(‘赢了‘+n)
        //     } catch (error) {
        //         console.log( ‘输了‘+error )

        //     }
        // }
        // test()

promise async await

原文:https://www.cnblogs.com/qydy/p/12263506.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!