当前位置:网站首页>Postman interface test | JS script blocking sleep and non blocking sleep
Postman interface test | JS script blocking sleep and non blocking sleep
2022-07-29 07:46:00 【Happy DAGO】
During the interface test , We often encounter that the previous interface has been called , Need to wait for a while , Then execute the scenario of the next interface .
programme 1: Blocking sleep waiting
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}
console.log(' wait for 1 Second .' )
sleep(1000)When executing the above code , Whole postman The interface will get stuck , The longer you wait , The longer it gets stuck , And I can't do anything else halfway ;
programme 2: Non blocking sleep wait
const sleep = time => {
return new Promise(resolve => setTimeout(resolve, time)
)
}
console.log(' wait for 10 Second , The current total is 0/60 second ')
sleep(60000)
console.log(' wait for 10 Second , The current total is 60/60 second ')Although and scheme 1 There's no big difference , however postman The interface is not stuck , When the waiting time arrives , Then the subsequent operations will be performed automatically , Therefore, it is recommended to use the scheme 2.
边栏推荐
- Cfdiv1+2-bash and a high math puzzle- (gcd+ summary of segment tree single point interval maintenance)
- RoBERTa:A Robustly Optimized BERT Pretraining Approach
- 【FPGA教程案例42】图像案例2——通过verilog实现图像二值化处理,通过MATLAB进行辅助验证
- How to get to the deep-water area when the industrial Internet goes?
- Technology sharing | quick intercom integrated dispatching system
- Dilworth 定理
- 08 dynamic programming
- [daily question in summer] Luogu p6408 [coci2008-2009 3] pet
- @Use of jsonserialize annotation
- [summer daily question] Luogu p6320 [coci2006-2007 4] sibice
猜你喜欢
随机推荐
10 practical uses of NFT
Do you want to meet all the needs of customers
[summer daily question] Luogu p6461 [coci2006-2007 5] trik
Dilworth 定理
新生代公链再攻「不可能三角」
Matlab simulation of LDPC minimum sum decoding based on high-order six ring free
[summer daily question] Luogu p4414 [coci2006-2007 2] ABC
[MySQL] - [subquery]
Realize the effect of changing some colors of a paragraph of text
What are the answers about older bloggers?
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
[summer daily question] Luogu p1601 a+b problem (high precision)
黑盒测试常见错误类型说明及解决方法有哪些?
Pat class a 1154 vertex shading
Ionicons icon Encyclopedia
CFdiv1+2-Bash and a Tough Math Puzzle-(线段树单点区间维护gcd+总结)
After the access database introduces DataGridView data, an error is displayed
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
State machine DP 3D
Technology sharing | quick intercom integrated dispatching system







