Why my array suddenly lose all its content

Jerome

I have read some posts that are related with my question but I'm a bit lost. What I'm trying to do is to add values of a collection in a Array and value of Docker in an other one. I can put the values in the 2 arrays but suddently the seconde one lose all his data.
There is my code:

triggerState = Meteor.bindEnvironment(function() {
  console.log("Start triggerState");

  //clean the 2 arrays
  stateLastCheck.length = 0;
  stateDockerLastCheck.length = 0;

  //add the collection value in the array
  InfosContainers.find().forEach(Meteor.bindEnvironment(function(ctn) {
    stateLastCheck.push(ctn.stateContainer);
    console.log("stateLastCheck " + stateLastCheck.length);
  }));
  console.log("end stateLastchek");

  //take the actual values
  docker.listContainers({
    all: true
  }, Meteor.bindEnvironment(function(err, containers) {
    containers.forEach(function(containerInfo) {
      stateDockerLastCheck.push(containerInfo.State);
      console.log("stateDockerLastCheck" + stateDockerLastCheck.length);
    });
  }));
  console.log("end stateDockerLastCheck");

  //compare last with actual
  for (var i = 0; i < stateLastCheck.length; i++) {
    console.log("Size of last and docker: " + stateLastCheck.length + " et " + stateDockerLastCheck.length);
    if (stateLastCheck[i].includes(stateDockerLastCheck[i])) {
      console.log("no problemos")
    } else {
      console.log("there is a changement of state:  " + stateLastCheck[i] + stateDockerLastCheck[i]);
      break;
    }
  }
  setTimeout(triggerState, 7000);
});

Then if I use my logs I can see that suddently the docker array is empty and that the loop is made again: enter image description here

I think I should use some wait but I'm really lost so if someone could help me ?

After adding some '---' in my code I noticed that the input is really strange : enter image description here

Amit Jamwal

I think the response for the docker is coming late and your for loop is executed before that and that is why your second array is empty

Try to use promises.

Hope this helps...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my array lose its mask after doing multidimensional indexing in Numpy?

From Dev

Why does my array lose its mask after doing multidimensional indexing in Numpy?

From Dev

Why am I suddenly signed out of all of my internet accounts?

From Dev

Why did all my folder dates suddenly change?

From Dev

Why is my Bootstrap column not centering its content?`

From Dev

Why does my object lose its resizable attribute and how do I get it back?

From Dev

Why does a string lose its value?

From Dev

Why is my border in the section wrapping all the content?

From Dev

Why do ALL of my git repositories suddenly show that everything has been deleted?

From Dev

Why my model in post lose dropdownlist items?

From Dev

Why is wrap causing my input to lose blur?

From Dev

Why doesn't my IOstat change its output at all?

From Dev

Cloning an array with its content

From Dev

Why is my mouse cursor coordinates suddenly scaled?

From Dev

Why are my browsers suddenly configured to use a proxy?

From Dev

WHY are my formulas suddenly not calculating on Excel?

From Dev

Why has my rankings suddenly dropped on google?

From Dev

Why there are suddenly 3 Threads in my Java program?

From Dev

Why did my username suddenly add @dhcp?

From Dev

Why is my Ubuntu laptop freezing suddenly?

From Dev

Why is this fs.readFile loop not pushing its results to my array?

From Dev

Why is suddenly all the files in git marked deleted?

From Java

Why does a const reference to a reference lose its constness?

From Dev

Why does a const reference to a reference lose its constness?

From Dev

Why doesn't my <li> expand width to cover all the content?

From Dev

Why is the new SkyDrive client not syncing all of my content?

From Dev

Why is all content on my home page overflowing the body border?

From Dev

Why my dropdown content is the same for all buttons I have

From Dev

why does Windows 7 x64 Explorer.exe suddenly gobble up all available RAM and slow my system to a crawl?

Related Related

  1. 1

    Why does my array lose its mask after doing multidimensional indexing in Numpy?

  2. 2

    Why does my array lose its mask after doing multidimensional indexing in Numpy?

  3. 3

    Why am I suddenly signed out of all of my internet accounts?

  4. 4

    Why did all my folder dates suddenly change?

  5. 5

    Why is my Bootstrap column not centering its content?`

  6. 6

    Why does my object lose its resizable attribute and how do I get it back?

  7. 7

    Why does a string lose its value?

  8. 8

    Why is my border in the section wrapping all the content?

  9. 9

    Why do ALL of my git repositories suddenly show that everything has been deleted?

  10. 10

    Why my model in post lose dropdownlist items?

  11. 11

    Why is wrap causing my input to lose blur?

  12. 12

    Why doesn't my IOstat change its output at all?

  13. 13

    Cloning an array with its content

  14. 14

    Why is my mouse cursor coordinates suddenly scaled?

  15. 15

    Why are my browsers suddenly configured to use a proxy?

  16. 16

    WHY are my formulas suddenly not calculating on Excel?

  17. 17

    Why has my rankings suddenly dropped on google?

  18. 18

    Why there are suddenly 3 Threads in my Java program?

  19. 19

    Why did my username suddenly add @dhcp?

  20. 20

    Why is my Ubuntu laptop freezing suddenly?

  21. 21

    Why is this fs.readFile loop not pushing its results to my array?

  22. 22

    Why is suddenly all the files in git marked deleted?

  23. 23

    Why does a const reference to a reference lose its constness?

  24. 24

    Why does a const reference to a reference lose its constness?

  25. 25

    Why doesn't my <li> expand width to cover all the content?

  26. 26

    Why is the new SkyDrive client not syncing all of my content?

  27. 27

    Why is all content on my home page overflowing the body border?

  28. 28

    Why my dropdown content is the same for all buttons I have

  29. 29

    why does Windows 7 x64 Explorer.exe suddenly gobble up all available RAM and slow my system to a crawl?

HotTag

Archive