Skip to main content
added 480 characters in body
Source Link
MIDE11
  • 3.7k
  • 7
  • 40
  • 58

I have the following code:

for (var i = 0; i < files.length; i++) {
    var data = fs.readFileSync(files[i]);
    fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

Edit:

This code is part of a server code, using express. We get a lot of https request, and serves the client. One of the operation is to appends files of 1MB to one big file. The server should return 200 if the operation success, 500 otherwise.

The problem is that if the code above (the for loop) is executed, The express module stop serving other clients, and it "busy" with this request. I try to use async.eachSeries (because the order of the files has a meaning, so I have to use Series method), but it still stucks the server.

I have the following code:

for (var i = 0; i < files.length; i++) {
    var data = fs.readFileSync(files[i]);
    fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

I have the following code:

for (var i = 0; i < files.length; i++) {
    var data = fs.readFileSync(files[i]);
    fs.appendFileSync("file_part", data);
}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

Edit:

This code is part of a server code, using express. We get a lot of https request, and serves the client. One of the operation is to appends files of 1MB to one big file. The server should return 200 if the operation success, 500 otherwise.

The problem is that if the code above (the for loop) is executed, The express module stop serving other clients, and it "busy" with this request. I try to use async.eachSeries (because the order of the files has a meaning, so I have to use Series method), but it still stucks the server.

deleted 32 characters in body
Source Link
JLRishe
  • 102.2k
  • 20
  • 139
  • 171

I have the following code:

        for (var i = 0; i < files.length; i++) {
                var data = fs.readFileSync(files[i]);
                fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

I have the following code:

        for (var i = 0; i < files.length; i++) {
                var data = fs.readFileSync(files[i]);
                fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

I have the following code:

for (var i = 0; i < files.length; i++) {
    var data = fs.readFileSync(files[i]);
    fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?

Source Link
MIDE11
  • 3.7k
  • 7
  • 40
  • 58

Node.js / Is for loop is Async?

I have the following code:

        for (var i = 0; i < files.length; i++) {
                var data = fs.readFileSync(files[i]);
                fs.appendFileSync("file_part", data);
)}

Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?

If it sync, how I make it async? so each iterate will be async?