Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
my object is modified inside a function that has a promise even if function returned

i have the following function that should return a result object

function checkRegisteredStatus(addr)
{
  let result ={status:"",registrationType:""};
  instance.methods.isRegistered(session.id,addr).call().then((receipt)=>
  {
    let {status,registrationType}= receipt;  
    result["status"] = status;
    result["registrationType"]= registrationType;
  });
  return result;
}

i want to use this function like this:

let result = checkRegisteredStatus(addr)
  • i have three problems :

1- when i used async/await pattern on isRegistered() method like this:

    let result = await instance.methods.isRegistered(session.id,addr).call();
    return result;

result object would be a promise with unfulfilled status, which is wired since the purpose of await is to return the result of the resolve callback, and this is the first time that happens to me, i did async/await before and it always returns the final result not a promise. why is this happening?

2- due to the first problem i had to re-write my function the old way which is using.then() method (as i pasted above) and it works, however i dont understand how come the checkRegisteredStatus function should finish execution and is popped off from the call stack then how is it being able to modify the result object?

Example:
let result = checkRegisteredStatus(addr)
console.log(result)

the output would be:

> {status:"",registration:""}

when i click the expand sign > it outputs the following:

 > {status:"",registration:""}
      registrationType: "NotRegistered"
      status: false

as far as i understand the value was caught be console.log() when the result object still had empty properties that's why i could expand the object and see its props have different values,i think JS is adding elements from inside that promise that registered before, but the function result obj should be cleaned from the stack (since it returns immediately), how is it adding values to it even though the function is popped from the call-stack?

3- how should i rewrite my function such that it blocks execution until it returns the final result not a promise and not adding up values later.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!