1

I'm currently refactoring some code, and I'm running into a problem.

I am trying to return the value from inside an anonymous function. I played around with it a few different ways, and tried await-ing it.

Essentially I'm getting data about the request that's being made, not the data from the request.

Here are some different ways I've tried working with it -

const run = async (text) => {
  ...
  const s = personalityInsights.profile(req, (err, data) => {
    ...
    return data; // correct value
  });

  return s; // incorrect value
};

const run = async (text) => {
  ...
  personalityInsights.profile(req, (err, data) => {
    ...
    return data;
  });
};

const run = async (text) => {
  ...
  return personalityInsights.profile(req, (err, data) => {
    ...
    return data;
  });
};

I can give the full code, but I think this is more of a language specific problem I have, than a code specific one.

Thanks for your help, Ollie

Edit: This question has been marked as a duplicate, which I understand - but the solutions in that duplicate simply aren't working, and they aren't things I haven't already tried...

Ollie
  • 1,104
  • 7
  • 24
  • 45
  • I've tried playing around with it, and a lot of my own solutions are the same as the ones listed, and it's still not working out - I'm not sure this is an exact duplicate problem – Ollie Sep 05 '18 at 11:08
  • You need to make a promise for the data so that you can `await` it within your function – Bergi Sep 05 '18 at 12:40

0 Answers0