Skip to content

Commit 2b01d41

Browse files
committed
improve iteration multiplexing
1 parent 148575b commit 2b01d41

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/dictionary/watch.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { Parser } from "./parallel_parser.ts";
99
// deno-lint-ignore require-yield
1010
async function* errorOnly(promise: Promise<never>): AsyncGenerator<never> {
1111
await promise;
12-
unreachable();
12+
}
13+
async function* addOneBefore<T>(
14+
first: T,
15+
iterable: AsyncIterable<T>,
16+
): AsyncGenerator<T> {
17+
yield first;
18+
yield* iterable;
1319
}
1420
if (import.meta.main) {
1521
using watcher = Deno.watchFs("./dictionary.txt");
@@ -29,12 +35,10 @@ if (import.meta.main) {
2935
});
3036
}, 200);
3137

32-
const watcherWithError = new MuxAsyncIterator<Deno.FsEvent>();
33-
watcherWithError.add(watcher);
38+
const watcherWithError = new MuxAsyncIterator<null | Deno.FsEvent>();
39+
watcherWithError.add(addOneBefore(null, watcher));
3440
watcherWithError.add(errorGenerator);
3541

36-
buildDebounced();
37-
buildDebounced.flush();
3842
for await (const _ of watcherWithError) {
3943
buildDebounced();
4044
}

0 commit comments

Comments
 (0)