Jhn Jhn - 1 year ago 86
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.


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download