0

I have the following code:

async function myPromiseFunction() {
  return "test";
};

function processComment(params) {
    (async () => {
          console.log(await myPromiseFunction());
    })();
}

exports.main = processComment;

The only way to output HTML code to the DOM in this case (serverless function), is through return {"body": "<h1>Test</h1>"}.

The problem is, if I put return {"body": "<h1>Test</h1>"} inside of the Async, it does not work and just does not return anything - it only works inside the processComment function whilst it is outside an async.

How can I replace console.log(await myPromiseFunction()); with return {"body": await myPromiseFunction())?

I can only console.log the value, but how can I return it so that it gets outputted as HTML?

2
  • Can you not just add return to processComment() method like this? function processComment(params) { return (async () => { await myPromiseFunction(); })();} Commented Jul 12, 2022 at 18:19
  • @HarshTuwar How would I do that in the context of return {"body":val} - return {"body": (async () => { await myPromiseFunction(); })()}? Commented Jul 12, 2022 at 18:26

1 Answer 1

1

I think updating your processComment() method like this would do the trick. Please let me know if that doesn't work so I can update this answer :D

function processComment(params) {
    return (async () => {
          var data = await myPromiseFunction();
          return { "body": data };      
    })();
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks but doesn't work unfortunately, it just doesn't return anything
you have to put a return statement at the bottom
@AlexanderMills Do you have an example of that? I put the return statement they have in their example
Thanks for pointing that out Alexander! @ewfewfjio, missed one more return statement. Check if this works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.