Hi i have a problem where i'm trying to iterate over a list of keys, creating a list of matching entities The code looks like this
let previous = undefined;
for (let i = offset; i < response.keys.length; i++) {
logger.debug("iteration " + i + " previous: " + previous)
logger.debug("instance key: " + response.keys[i])
if (previous) {
previous = previous
.then((entities) => {
if (entities.length === limit) {
i = response.keys.length;
} else {
readEntity(response.keys[i])
.then((instance) => {
matchInstance(instance, conditions)
logger.debug("is match: " + isMatch)
.then((isMatch) => {
if (isMatch)
entities.push(instance);
//resolve(entities);
}).catch((err) => {
reject(err)
})
}).catch((err) => {
reject(err)
})
}
}).catch((err) => {
reject(err)
})
} else {
previous = readEntity(response.keys[i])
.then((instance) => {
logger.debug("reading instance: " + instance.key)
matchInstance(instance, conditions)
.then((isMatch) => {
if (isMatch) {
return instance
} else {
logger.debug("instance does not match")
}
}).catch((err) => {
reject(err)
})
}).catch((err) => {
reject(err)
})
}
}
but it only goes through the for loop once, like, it isn't returning anything?
i have some debugging aswell
2017-10-04T15:09:58+0200 <debug> data.js:202 (seekKeys.then) iteration 0 previous: undefined
2017-10-04T15:09:58+0200 <debug> data.js:203 (seekKeys.then) instance key: employees/existing@...
2017-10-04T15:09:58+0200 <debug> data.js:202 (seekKeys.then) iteration 1 previous: [object Promise]
2017-10-04T15:09:58+0200 <debug> data.js:203 (seekKeys.then) instance key: employees/test@...
2017-10-04T15:09:58+0200 <debug> data.js:202 (seekKeys.then) iteration 2 previous: [object Promise]
2017-10-04T15:09:58+0200 <debug> data.js:203 (seekKeys.then) instance key: employees/unique@...
2017-10-04T15:09:58+0200 <debug> data.js:202 (seekKeys.then) iteration 3 previous: [object Promise]
2017-10-04T15:09:58+0200 <debug> data.js:203 (seekKeys.then) instance key: employees/update@...
2017-10-04T15:09:59+0200 <debug> data.js:231 (readEntity.then) reading instance: existing@...
2017-10-04T15:09:59+0200 <debug> data.js:237 (matchInstance.then) instance does not match
please let me know if you need more info. Thank you