当前位置:网站首页>Promise usage scenarios
Promise usage scenarios
2022-06-24 08:23:00 【Nanjing front end】
1.await && async Keyword waiting for request
async function test(){
var message = await new Promise((resolve,reject)=>{
setTimeout(function(){
resolve("{message:'hello'}")
},3000)
})
.then(value=>{ return JSON.parse(value) })
.then(value=>{
return value
})
console.log(message)
}2. Step by step request
var message = new Promise((resolve,reject)=>{
// Request verification before formal request
setTimeout(function(){
resolve('success')
},3000)
}).then(value=>{
if(value=='success'){// Authentication succeeded
return new Promise((resolve,reject)=>{
setTimeout(function(){
resolve({username:'xx'})
},3000)
})
}
})
message.then(res=>{
console.log(res.username)
})边栏推荐
猜你喜欢

Synthesize video through ffmpeg according to m3u8 file of video on the network

2021-03-11 COMP9021第八节课笔记

2021-03-09 COMP9021第七节课笔记

Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022

2021-03-04 COMP9021第六节课笔记

WCF TCP protocol transmission

Installation and use of selenium IDE

根据网络上的视频的m3u8文件通过ffmpeg进行合成视频

More appropriate development mode under epidemic situation

疫情下更合适的开发模式
随机推荐
Swift 基础 Swift才有的特性
疫情下更合适的开发模式
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
Coordinate transformation of graphic technology
2021-03-11 COMP9021第八节课笔记
自动化测试的未来趋势
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
【无标题】
05-ubuntu安装mysql8
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
Question 3 - MessageBox pop-up box, modify the default background color
How to use the virtual clock of FPGA?
Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
Robot acceleration level task priority inverse kinematics
More appropriate development mode under epidemic situation
List of Li Bai's 20 most classic poems
1279_ Vsock installation failure resolution when VMware player installs VMware Tools
Nodejs redlock notes
JS scroll div scroll bar to bottom
51单片机_外部中断 与 定时/计数器中断