node异步读取文件的陷阱
来源:互联网 发布:mac os无法安装 编辑:程序博客网 时间:2024/06/18 17:45
node是可以异步读取文件,但是如果一下子异步读取的数量过大,则会抛出20错误
以下列出3种读取方式:同步,异步转同步,数量约束的异步
var t1, t2;t1 = +new Date;fileList.forEach(function(n, i) {var data = fs.readFileSync(n, {encoding: "utf-8"});if (data && data.indexOf && data.indexOf("templateUrl: 'templates/widget-label.html'") >= 0) {console.log(n);}});t2 = +new Date;console.log(t2 - t1);t1 = +new Date;async.eachSeries(fileList, function(n, callback) {fs.readFile(n, "utf-8", function() {// to do callback(null, null);})}, function(err) {t2 = +new Date;console.log(t2 - t1);console.log("eachSeries end");})/*t1 = +new Date;fileList.forEach(function(n, i) {fs.readFile(n, "utf-8", function(err, data) {// to do });});t2 = +new Date;console.log(t2 - t1);*/t1 = +new Date;async.eachLimit(fileList, 500, function(n, callback) {fs.readFile(n, "utf-8", function() {// to do callback(null, null);})}, function(err) {t2 = +new Date;console.log(t2 - t1);console.log("eachLimit end");});
时间分别为2564,4007,1207
(我的文件夹下有3000个文件)
0 0
- node异步读取文件的陷阱
- Node.js学习-----------异步文件读取
- node 异步读取文件路径处理
- node 异步与同步读取文件
- node 操作文件流 fs 同步与异步 流式文件的写入与读取
- Node.js的读取文件的异步过程基础的讲解
- node批量读取文件时异步变同步的方法分享
- Node.js文件的读取
- Node.js For 循环 异步陷阱
- node.js读取本地的文件
- Node的简单读取文件内容
- nodejs异步读取文件与同步读取文件的区别
- node.js 循环的陷阱
- Node.js读取文件
- node文件读取流
- Node.js 读取文件
- 异步读取大文件的改进
- 异步读取大文件的改进
- inline函数_内联函数的一些总结
- SCANV团队预警libsys图书馆系统注入漏洞
- OpenglES 中名词缩写
- 运用命令提示符查询卷序列号
- SCANV团队预警BocWebCMS系统高危漏洞
- node异步读取文件的陷阱
- 软工二
- android 各组件
- 对比多张图片的灰阶
- AIR程序生成系统托盘
- 如何写出百度非常青睐的文章?
- Android TextView 高级应用
- oracle goldengate 参数学习 GETUPDATEBEFORES
- 黑马程序员-关于线程继承Thread和Runnable的对比