Home NodeJS storing iterator position over requests
Reply: 0

NodeJS storing iterator position over requests

user1497
1#
user1497 Published in July 18, 2018, 10:22 pm

We have written some code that returns an array from a database and on the first request, we loop over it until we find the variable. and then send that value.

However, if we also have a second request that request starts iterating at the position we left the previous loop on.

result.findAllLights(function (lights) {
            console.log("got callback");
            var send = false;
            delete lightId;
            console.log("PRE-LOOP = " + JSON.stringify(lights));


            for (var lightId in lights) {
                console.log("checking " + lightId);

and this produces

checking 0
light.column=0 and row = 0 and 1 and 1
checking 1
light.column=0 and row = 1 and 1 and 1
checking 2
light.column=0 and row = 2 and 1 and 1
checking 3
light.column=0 and row = 3 and 1 and 1
checking 4
light.column=0 and row = 4 and 1 and 1
checking 5
light.column=1 and row = 0 and 1 and 1
checking 6
light.column=1 and row = 1 and 1 and 1
found light

and when the second request is in this is the output

checking 7
light.column=1 and row = 2 and 1 and 1
checking 8
light.column=1 and row = 3 and 1 and 1
checking 9
light.column=1 and row = 4 and 1 and 1
checking 10
light.column=2 and row = 0 and 1 and 1
checking 11
light.column=2 and row = 1 and 1 and 1
checking 12
light.column=2 and row = 2 and 1 and 1
checking 13
light.column=2 and row = 3 and 1 and 1
checking 14
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.431212 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO