Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jerel Miller <[email protected]>
  • Loading branch information
phryneas and jerelmiller authored Oct 4, 2023
1 parent 42774bc commit 2ba8d99
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/testing/internal/ObservableTaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ type ObservableEvent<T> =
| { type: "complete" };

async function* observableToAsyncEventIterator<T>(observable: Observable<T>) {
let resolveNext: undefined | ((value: ObservableEvent<T>) => void);
let resolveNext: (value: ObservableEvent<T>) => void;
const promises: Promise<ObservableEvent<T>>[] = [];
pushPromise();

function pushPromise() {
promises.push(
new Promise<ObservableEvent<T>>((resolve) => {
resolveNext = resolve;
resolveNext = (event: ObservableEvent<T>) => {
resolve(event)
pushPromise();
};
})
);
}

function onValue(value: ObservableEvent<T>) {
resolveNext!(value);
pushPromise();
}
observable.subscribe(
(value) => onValue({ type: "next", value }),
(error) => onValue({ type: "error", error }),
() => onValue({ type: "complete" })
(value) => resolveNext({ type: "next", value }),
(error) => resolveNext({ type: "error", error }),
() => resolveNext({ type: "complete" })
);

while (true) {
Expand Down

0 comments on commit 2ba8d99

Please sign in to comment.