How to delay a function returning a value before response from database? [duplicate]
How to delay a function returning a value before response from database? [duplicate] This question already has an answer here: I have a function which modifies a variable as per response from database. function f () { let x = { }; redis.get ("key1").then ( value => x.prop1 = value); redis.get ("key2").then ( value => x.prop2 = value); return x; } This is my code roughly. It is actually in a for loop, using node-redis. I have multiple calls to Redis. I add the data from Redis to a new object and return the object. PROBLEM: function f () is returning an empty object every time I call it. f () How do I wait for all Redis promises to resolve before returning the object? This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 Answer 1 In your code, you are not waiting f...