In the following code, async.series blocks are not executing in sequence.
var fs = require("fs");
var async = require("async");
var buffer = new Buffer(10);
var read = "";
var readByt;
async.series([
function(callback) {
console.log("test");
callback();
},
function(callback) {
fs.open('c:/ab.txt', 'r+', function(err, fd) {
fs.read(fd, buffer, 0, buffer.length, 0, function(err, bytes){
read = buffer.slice(0, bytes).toString();
readByt = bytes;
console.log("}}}"+read);
fs.close(fd, function(err){
if (err){
console.log(err);
}
console.log("File closed successfully.");
})
})
})
callback();
},
function (callback){
console.log("console:"+read);
console.log("console:"+read.substr(read.length-1));
console.log("console:"+buffer.slice(0, readByt).toString());
callback();
}
],function(){});
On executing via command line the buffer printing in the third block happens before the file read operations.
c:\>node fr.js
test
console:
console:
console: ?F p?
}}}c:/log.txt
File closed successfully.
How to get these execute in sequence?
via ManFriday
No comments:
Post a Comment