DVLP / signalr-no-jquery

120 stars 78 forks source link

How will I notify you after the message arrives #45

Closed 10ur10der closed 5 years ago

10ur10der commented 5 years ago
 let mes :string;
 const connection = hubConnection('http://domain.com/');
 const hubProxy = connection.createHubProxy('signalrserver');
connection.start()
  .done(function(){ 
    console.log('Now connected, connection ID=' + connection.id);  
     hubProxy.invoke('sendMessages');
  })
 .fail(function(){ console.log('Could not connect'); });
 hubProxy.on('sendMessages', function(message) {        
  mes = message;
 console.log("abc", mes);
  });
 console.log("cba", mes); 

Message from SignalR is coming. I want to send notification to the user after receiving the message.but out of function message undefined.what would be the reason

console.log("abc", mes)->message is displayed in console. console.log("cba", mes)->message is not displayed in console.result -> cba undefined

 `this.localNotifications.schedule({
   id: 1,
   text: mes
  });`
DVLP commented 5 years ago

mes in undefined because "cba" is called before the asynchronous callback gets executed