Jhn Jhn - 4 months ago 11
Javascript Question

How to get a value from a callback?

I have this line of codes:

let message = channel.consume(queue, msg => {
console.log('Return this in the "message" variable', msg.content);

When I tried to log the value of
, it does not equate to
but it gets the value from the return of
method. What's the workaround in order for me to get the right value from the callback.


var message;
channel.consume(queue, msg => { message = msg.content; });

Not really sure what you're asking, but are you trying to set message within the callback? If so, see above.