Skip to content

Commit

Permalink
refactor: dont extend Array
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Viglucci <[email protected]>
  • Loading branch information
viglucci committed Jun 21, 2023
1 parent 2f51d02 commit f4419b0
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ import {
} from "rsocket-core";
import { Codec } from "rsocket-messaging";
import { Observer, Subscription } from "rxjs";
import { applyMixins } from "./Utils";

interface ObserverToBufferingRSocketSubscriber<T>
extends Subscription,
Array<T>,
Observer<T>,
Cancellable,
Requestable,
OnExtensionSubscriber {}

class ObserverToBufferingRSocketSubscriber<T>
extends Subscription
implements Observer<T>, Cancellable, Requestable, OnExtensionSubscriber
{
protected wip: number = 0;
private e: Error;
private done: boolean;
private stack: T[];

constructor(
protected requested: number,
Expand All @@ -48,6 +48,7 @@ class ObserverToBufferingRSocketSubscriber<T>
protected readonly inputCodec: Codec<T>
) {
super();
this.stack = [];
}

request(n: number) {
Expand Down Expand Up @@ -78,7 +79,7 @@ class ObserverToBufferingRSocketSubscriber<T>
): void {}

next(value: T) {
this.push(value);
this.stack.push(value);

this.drain();
}
Expand Down Expand Up @@ -117,7 +118,7 @@ class ObserverToBufferingRSocketSubscriber<T>
let requested = this.requested;
let delivered = 0;
while (delivered < requested) {
const next = this.shift();
const next = this.stack.shift();

if (next == undefined) {
if (this.done) {
Expand All @@ -136,7 +137,7 @@ class ObserverToBufferingRSocketSubscriber<T>
break;
}

const isTerminated = this.length == 0 && this.done;
const isTerminated = this.stack.length == 0 && this.done;
this.subscriber.onNext(
{
data: this.inputCodec.encode(next),
Expand All @@ -162,6 +163,4 @@ class ObserverToBufferingRSocketSubscriber<T>
}
}

applyMixins(ObserverToBufferingRSocketSubscriber, [Array]);

export default ObserverToBufferingRSocketSubscriber;

0 comments on commit f4419b0

Please sign in to comment.