Skip to content

Commit

Permalink
Merge pull request #819 from thefrontside/fix-website
Browse files Browse the repository at this point in the history
Fix website vi async iterator adapter
  • Loading branch information
cowboyd authored Nov 2, 2023
2 parents ed7eddf + 69be00d commit ff2d173
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function expect<T>(promise: Promise<T>): Operation<T> {

export function subscribe<T, R>(iter: AsyncIterator<T, R>): Subscription<T, R> {
return {
next: () => call(iter.next),
next: () => call(() => iter.next()),
};
}

Expand Down
26 changes: 16 additions & 10 deletions www/lib/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
pipe,
resource,
run,
first,
sleep,
type Stream,
stream,
Expand Down Expand Up @@ -32,7 +33,8 @@ await run(function* () {
try {
while (true) {
yield* action(function* (restart) {
let changes = yield* pipe(

let change = pipe(
useFsWatch(paths),
filter(function* (event) {
return !event.paths.some((path) =>
Expand All @@ -43,7 +45,7 @@ await run(function* () {

yield* useCommand(cmd, { args });

yield* changes.next();
yield* first(change);

yield* sleep(100);

Expand All @@ -59,13 +61,17 @@ await run(function* () {
});

function useFsWatch(paths: string | string[]): Stream<Deno.FsEvent, never> {
return resource(function* (provide) {
let watcher = Deno.watchFs(paths);
try {
let subscription = yield* stream(watcher);
yield* provide(subscription as Subscription<Deno.FsEvent, never>);
} finally {
watcher.close();
return {
subscribe() {
return resource(function* (provide) {
let watcher = Deno.watchFs(paths);
try {
let subscription = yield* stream(watcher).subscribe();
yield* provide(subscription as Subscription<Deno.FsEvent, never>);
} finally {
watcher.close();
}
});
}
});
}
}

0 comments on commit ff2d173

Please sign in to comment.