JavaScript Typescript Async/Await with SignalR Function typescript async await,typescript async await example,typescript async await

I have encountered a problem where a sequence of SignalR hub function fails to be executed asynchronously.

I have:

//Hub functions
//Initializing hub server and clients.
function HubStart() {
    $.connection.hub.start().then(function () {
        console.log(1);
        return new Promise(resolve => resolve);
    });
}
//Hub server-side function that add user's name to chat board.
function HubUserOnline(user: any) {
    $.connection.boardHub.server.userOnline(user).then(resolve => { return new Promise(resolve => resolve); });
}

//Main
var viewModel = ko.mapping.fromJS(model, mappingOption);
main();

//Definition of the main function
async function main() {
    console.log(0);
    await HubStart();
    console.log(2);
    await HubUserOnline(ko.mapping.toJS(viewModel.CurrentUser))
    console.log(3);
    }
});

However, the console says:

> 0
> 2
> Uncaught (in promise) Error: SignalR: Connection must be started before data can be sent. Call .start() before .send()
>   at hubConnection.fn.init.send (jquery.signalR-2.2.1.js:780)
>   at init.invoke (jquery.signalR-2.2.1.js:2734)
>   at Object.userOnline (hubs:120)
>   at HubUserOnline (WaitingRoom.ts:190)
>   at WaitingRoom.ts:203
>   at Generator.next (<anonymous>)
>   at fulfilled (WaitingRoom.ts:1)
> 1

Thus it indicates the second hub function was going to be executed before the hub instance had been created and it got an error.

The hub functions return JQueryPromise so I tried to let a function return a promise when the hub functions are completed. Can anybody indicate a fault in my code and trial?

Answer:1

Please take a look at these: import React, { Component } from 'react'; import { AppRegistry, Text, View } from 'react-native'; As you see, it imports something, but why React is out of {} and all ...

Please take a look at these: import React, { Component } from 'react'; import { AppRegistry, Text, View } from 'react-native'; As you see, it imports something, but why React is out of {} and all ...

  1. when should you write a functional (skills) résumé
  2. when should you write out numbers
  3. when should child write name
  4. when should i write my birth plan
  5. when should you write numbers as words
  6. when should child write their name
  7. when should you write the executive summary
  8. when should you write a business plan
  9. when should you write a cover letter
  10. when should you write the introduction and overview portion
  11. when should i write out numbers
  12. when should you write without prejudice on a letter
  13. when should you write a draft of your summary
  14. when should i write gre for fall 2020
  15. when should i write my college essay
  16. when should i write a cover letter
  17. when should i write numbers as words
  18. when should we write gate exam

To the best of my knowledge, I am doing the same thing using 2 different approaches: const https = require("https"); const axios = require("axios"); let httpsAgent = new https.Agent({...

To the best of my knowledge, I am doing the same thing using 2 different approaches: const https = require("https"); const axios = require("axios"); let httpsAgent = new https.Agent({...

I am new to EXTJS. Now im trying to develop simple pivot grid example. my code is: Ext.onReady(function () { var myStore = new Ext.data.ArrayStore({ autoLoad: true, fields: ['gender', ...

I am new to EXTJS. Now im trying to develop simple pivot grid example. my code is: Ext.onReady(function () { var myStore = new Ext.data.ArrayStore({ autoLoad: true, fields: ['gender', ...

  1. extjs pivot grid example
  2. extjs pivot grid
  3. extjs pivot grid fiddle
  4. extjs pivot grid demo
  5. extjs pivot grid kitchen sink
  6. extjs pivot grid store
  7. extjs pivot grid export
  8. extjs 6 pivot grid example
  9. extjs 6 pivot grid
  10. extjs 4 pivot grid example
  11. extjs 6.2 pivot grid
  12. extjs pivotgrid leftaxis

I'm trying to hide a div when the user clicks anywhere outside of the div with id "main". I am using vanilla Javascript and would prefer not to use jQuery. The code I have works well but whenever ...

I'm trying to hide a div when the user clicks anywhere outside of the div with id "main". I am using vanilla Javascript and would prefer not to use jQuery. The code I have works well but whenever ...

  1. hiding elements with javascript
  2. hiding div with javascript
  3. hiding javascript code
  4. hiding javascript
  5. hiding javascript source code
  6. hiding javascript from view source
  7. hiding javascript in image
  8. hiding javascript code view source
  9. hiding javascript in html
  10. hiding javascript from incompatible browsers
  11. hiding javascript from old browsers
  12. hiding html elements with javascript
  13. hiding a button with javascript
  14. hiding a href with javascript