Jhn Jhn - 2 months ago 5
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
message
, it does not equate to
msg.content
but it gets the value from the return of
consume
method. What's the workaround in order for me to get the right value from the callback.

Thanks

Answer
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.

Comments