Release v23.038 (from e012cb8f)
Fixes tradingview/charting_library#4522 Fixes tradingview/charting_library#5348 Fixes tradingview/charting_library#5573 Fixes tradingview/charting_library#5726 Fixes tradingview/charting_library#6039 Fixes tradingview/charting_library#6215 Fixes tradingview/charting_library#6500 Fixes tradingview/charting_library#6550 Fixes tradingview/charting_library#6559 Fixes tradingview/charting_library#6572 Fixes tradingview/charting_library#6617 Fixes tradingview/charting_library#6659 Fixes tradingview/charting_library#6678 Fixes tradingview/charting_library#6695 Fixes tradingview/charting_library#6713 Fixes tradingview/charting_library#6714 Fixes tradingview/charting_library#6737 Fixes tradingview/charting_library#6767 Fixes tradingview/charting_library#6783 Fixes tradingview/charting_library#6800 Fixes tradingview/charting_library#6825
This commit is contained in:
@@ -30,16 +30,20 @@ const enum UpdateTimeouts {
|
||||
General = 60 * 1000,
|
||||
}
|
||||
|
||||
interface Timers {
|
||||
fastTimer: number;
|
||||
generalTimer: number;
|
||||
}
|
||||
|
||||
export class QuotesPulseProvider {
|
||||
private readonly _quotesProvider: IQuotesProvider;
|
||||
private readonly _subscribers: QuoteSubscribers = {};
|
||||
private _requestsPending: number = 0;
|
||||
|
||||
private _timers: Timers | null = null;
|
||||
|
||||
public constructor(quotesProvider: IQuotesProvider) {
|
||||
this._quotesProvider = quotesProvider;
|
||||
|
||||
setInterval(this._updateQuotes.bind(this, SymbolsType.Fast), UpdateTimeouts.Fast);
|
||||
setInterval(this._updateQuotes.bind(this, SymbolsType.General), UpdateTimeouts.General);
|
||||
}
|
||||
|
||||
public subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: QuotesCallback, listenerGuid: string): void {
|
||||
@@ -48,15 +52,34 @@ export class QuotesPulseProvider {
|
||||
fastSymbols: fastSymbols,
|
||||
listener: onRealtimeCallback,
|
||||
};
|
||||
|
||||
this._createTimersIfRequired();
|
||||
logMessage(`QuotesPulseProvider: subscribed quotes with #${listenerGuid}`);
|
||||
}
|
||||
|
||||
public unsubscribeQuotes(listenerGuid: string): void {
|
||||
delete this._subscribers[listenerGuid];
|
||||
if (Object.keys(this._subscribers).length === 0) {
|
||||
this._destroyTimers();
|
||||
}
|
||||
logMessage(`QuotesPulseProvider: unsubscribed quotes with #${listenerGuid}`);
|
||||
}
|
||||
|
||||
private _createTimersIfRequired(): void {
|
||||
if (this._timers === null) {
|
||||
const fastTimer = setInterval(this._updateQuotes.bind(this, SymbolsType.Fast), UpdateTimeouts.Fast);
|
||||
const generalTimer = setInterval(this._updateQuotes.bind(this, SymbolsType.General), UpdateTimeouts.General);
|
||||
this._timers = { fastTimer, generalTimer };
|
||||
}
|
||||
}
|
||||
|
||||
private _destroyTimers(): void {
|
||||
if (this._timers !== null) {
|
||||
clearInterval(this._timers.fastTimer);
|
||||
clearInterval(this._timers.generalTimer);
|
||||
this._timers = null;
|
||||
}
|
||||
}
|
||||
|
||||
private _updateQuotes(updateType: SymbolsType): void {
|
||||
if (this._requestsPending > 0) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user