Skip to content

Commit

Permalink
Fix typos after review
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jul 7, 2020
1 parent 42cc283 commit 1cf2ad6
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Observable } from 'rxjs';

import * as Rx from 'rxjs';

export class AbortError extends Error {}

export const toPromiseAbortable = <T>(
observable: Observable<T>,
observable: Rx.Observable<T>,
signal?: AbortSignal
): Promise<T> =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -53,18 +53,18 @@ export function createLimiter(ratelimitIntervalMs: number, ratelimitRequestPerIn

let currentInterval: { startedAt: number; numRequests: number } = createCurrentInterval();
let observers: Array<[Rx.Subscriber<any>, any]> = [];
let timerSubsription: Rx.Subscription | undefined;
let timerSubscription: Rx.Subscription | undefined;

function createTimout() {
if (timerSubsription) {
function createTimeout() {
if (timerSubscription) {
return;
}
timerSubsription = Rx.asyncScheduler.schedule(() => {
timerSubsription = undefined;
timerSubscription = Rx.asyncScheduler.schedule(() => {
timerSubscription = undefined;
currentInterval = createCurrentInterval();
for (const [waitingObserver, value] of observers) {
if (currentInterval.numRequests >= ratelimitRequestPerInterval) {
createTimout();
createTimeout();
continue;
}
currentInterval.numRequests++;
Expand All @@ -75,7 +75,7 @@ export function createLimiter(ratelimitIntervalMs: number, ratelimitRequestPerIn

return function limit<T>(): Rx.MonoTypeOperatorFunction<T> {
return (observable) =>
new Observable<T>((observer) => {
new Rx.Observable<T>((observer) => {
const subscription = observable.subscribe({
next(value) {
if (currentInterval.numRequests < ratelimitRequestPerInterval) {
Expand All @@ -85,7 +85,7 @@ export function createLimiter(ratelimitIntervalMs: number, ratelimitRequestPerIn
}

observers = [...observers, [observer, value]];
createTimout();
createTimeout();
},
error(err) {
observer.error(err);
Expand Down

0 comments on commit 1cf2ad6

Please sign in to comment.