Home > Blockchain >  Does an un awaited promise get executed if the Lambda has already returned response
Does an un awaited promise get executed if the Lambda has already returned response

Time:06-08

Lets say I have a Node JS lambda, that goes like:

const _helper= async(){
  var dbResponse1= await getDataFromDB(); // 150 ms
  computation(dbResponse1);
  var dbResponse2= await dbTransaction(); // 3 separate db calls, 500 ms
  if (someCondition){
    await pushToNotificationQueue(); // 100 ms
  }
}

const handler= async(event, context)=> {
  var getData= await getDataFromDB();
  _helper();
  return {
    statusCode: 200,
    message: "",
    body: getData
  }
}

Will the promise returned by _helper be fulfilled or the return statement of hander is the end for _handler as well?

CodePudding user response:

You need to await your _helper function. Your lambda is terminated as soon as handler is done.

So back to your question:

...handler is the end for _handler as well

Yes

  • Related