Kelly Norton hace 11 meses
padre
commit
b005d5ee94
Se han modificado 2 ficheros con 8 adiciones y 6 borrados
  1. 1 1
      ui/src/LinksPage/RoutesContext/RoutesProvider.tsx
  2. 7 5
      ui/src/restartable.ts

+ 1 - 1
ui/src/LinksPage/RoutesContext/RoutesProvider.tsx

@@ -12,7 +12,7 @@ export const RoutesProvider = ({ children }: { children: ReactNode }) => {
   useEffect(() => {
     const fetchAllRoutes = async () => {
       const allRoutes = [];
-      for await (const routes of res()) {
+      for await (const routes of res) {
         allRoutes.push(...routes);
         setResult(Result.of(allRoutes));
       }

+ 7 - 5
ui/src/restartable.ts

@@ -1,9 +1,7 @@
-export function restartableAsync<T>(
-  iter: AsyncIterable<T>
-): () => AsyncIterable<T> {
+export function restartableAsync<T>(iter: AsyncIterable<T>): AsyncIterable<T> {
   // buffer stores all items that have been previously consumed.
   const buffer: T[] = [];
-  return async function* () {
+  const gen = async function* () {
     // index of the next item in the buffer to yield.
     let i = 0;
     // produce all items previously consumed by other iterators.
@@ -14,7 +12,7 @@ export function restartableAsync<T>(
     for await (const item of iter) {
       // this is a little subtle, but other concurrent iterators may have
       // consumed and buffered items while we were waiting. So we need to put
-      // our new item in the back of the buffer and yield from where we preiously
+      // our new item in the back of the buffer and yield from where we previously
       // left off.
       buffer.push(item);
       for (; i < buffer.length; i++) {
@@ -22,4 +20,8 @@ export function restartableAsync<T>(
       }
     }
   };
+
+  return {
+    [Symbol.asyncIterator]: () => gen(),
+  };
 }