<commit_before>import * as $ from 'jquery';
import 'signalr';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

import { SignalRError } from './signalr-error';
import { SignalRState, toSignalRState } from './signalr-state';

export class SignalRHub {
    private _connection: SignalR.Hub.Connection;
    private _proxy: SignalR.Hub.Proxy;
    private _state$: Subject<string>;
    private _error$: Subject<SignalRError>;
    private _subjects: { [name: string]: Subject<any> };

    get connection(): SignalR.Hub.Connection {
        return this._connection || (this._connection = this.createConnection());
    }

    get proxy(): SignalR.Hub.Proxy {
        return this._proxy || (this._proxy = this.connection.createHubProxy(this.hubName));
    }

    get hubName(): string {
        return this._hubName;
    }

    get url(): string  {
        return this._url;
    }

    get state$(): Observable<string> {
        return this._state$.asObservable();
    }

    get error$(): Observable<SignalRError> {
        return this._error$.asObservable();
    }

    constructor(private _hubName: string, 
        private _url: string = null) {
        this._subjects = {};
        this._state$ = new Subject<string>();
        this._error$ = new Subject<SignalRError>();
    }

    start() {
        if(!this.hasSubscriptions())
            console.warn('No listeners have been setup. You need to setup a listener before starting the connection or you will not receive data.');
        this.connection.start();
    }

    on<T>(event: string): Observable<T> {
        const subject =  this.getOrCreateSubject<T>(event);
        this.proxy.on(event, (data: T) => subject.next(data))
        return subject.asObservable();
    }

    send<T>(method: string, data: T) {
        this.proxy.invoke(method, data);
    }

    hasSubscriptions(): boolean {
        for (let key in this._subjects) {
            if (this._subjects.hasOwnProperty(key)) {
                return true;                
            }
        }

        return false;
    }<commit_msg>Added promise to send method of hub so it can return values<commit_after>import * as $ from 'jquery';
import 'signalr';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

import { SignalRError } from './signalr-error';
import { SignalRState, toSignalRState } from './signalr-state';

export class SignalRHub {
    private _connection: SignalR.Hub.Connection;
    private _proxy: SignalR.Hub.Proxy;
    private _state$: Subject<string>;
    private _error$: Subject<SignalRError>;
    private _subjects: { [name: string]: Subject<any> };

    get connection(): SignalR.Hub.Connection {
        return this._connection || (this._connection = this.createConnection());
    }

    get proxy(): SignalR.Hub.Proxy {
        return this._proxy || (this._proxy = this.connection.createHubProxy(this.hubName));
    }

    get hubName(): string {
        return this._hubName;
    }

    get url(): string  {
        return this._url;
    }

    get state$(): Observable<string> {
        return this._state$.asObservable();
    }

    get error$(): Observable<SignalRError> {
        return this._error$.asObservable();
    }

    constructor(private _hubName: string, 
        private _url: string = null) {
        this._subjects = {};
        this._state$ = new Subject<string>();
        this._error$ = new Subject<SignalRError>();
    }

    start() {
        if(!this.hasSubscriptions())
            console.warn('No listeners have been setup. You need to setup a listener before starting the connection or you will not receive data.');
        this.connection.start();
    }

    on<T>(event: string): Observable<T> {
        const subject =  this.getOrCreateSubject<T>(event);
        this.proxy.on(event, (data: T) => subject.next(data))
        return subject.asObservable();
    }

    async send<T>(method: string, data: T): Promise<any> {
        return this.proxy.invoke(method, data);
    }

    hasSubscriptions(): boolean {
        for (let key in this._subjects) {
            if (this._subjects.hasOwnProperty(key)) {
                return true;                
            }
        }

        return false;
    }
{'fraction_non_alphanumeric': 0.12779477524123323, 'fraction_numerical': 0.0, 'mean_word_length': 2.562447611064543, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5130559', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1184, 'n_words': 306}