2017-01-04 1 views
0

私の質問に関連するいくつかの記事を読みましたが、少し失われています。私がしようとしているのは、Arrayのコレクションの値とDockerの値を別の値に追加することです。私は2つの配列に値を入れることができますが、sundently secondeはすべての彼のデータを失う。 ​​私の配列が突然すべての内容を失う理由

は、私はいくつかを使用すべきだと思う:私は私のログを使用している場合、私はそのsuddentlyドッキングウィンドウの配列が空で、ループが再び行われることがわかります次に

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); 
}); 


は私のコードがありますwaitしかし、誰かが私を助けることができたら、私は本当に迷っていますか? enter image description here

+0

は私がドッキングウィンドウの応答が遅れて来ていると思うし、あなたのforループは、その前に実行されると、あなたの二番目の配列が空である理由です。 –

+0

@AmitJamwalので、私は待機方法を追加しようとします – Jerome

+1

あなたは正しいです!答えに入れて、私はそれをマークします – Jerome

答えて

0

は、私がドッキングウィンドウの応答が遅れて来ていると思うし、あなたのforループは、その前に実行され、それは次のとおりです。

は、追加した後、いくつかは、「---」私のコードで私は入力が本当に奇妙であることに気づきましたなぜあなたの2番目の配列は空です

約束を使用してみてください。このことができます

希望...

関連する問題