在快递中添加故意延迟 [英] Add intentional latency in express
本文介绍了在快递中添加故意延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在node.js中使用express,并测试了某些路由.我正在
Im using express with node.js, and testing certain routes. I'm doing this tute at http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/
我通过ajax调用http://localhost:3000/wines
(内容无关紧要).但是我想测试延迟. 2秒后,我可以做些使快递反应的事情吗? (我想模拟ajax加载程序,并且我在localhost上运行,所以我的等待时间几乎为零)
Im calling the http://localhost:3000/wines
via ajax (the content doesn't matter). But I want to test latency. Can I do something like make express respond after 2 seconds? (I want to simulate the ajax loader and I'm running on localhost so my latency is pretty much nil)
推荐答案
只需在 setTimeout setTimeout 内调用res.send
即可. a>:
Just call res.send
inside of a setTimeout:
setTimeout((function() {res.send(items)}), 2000);
这篇关于在快递中添加故意延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文