mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
1b6f831875
Following JS ops were moved to separate files in cli/js/ops directory: - compiler - dispatch_json - dispatch_minimal - errors - fetch - fs_events - os - random - repl - resources - runtime_compiler - runtime - tty
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Copyright 2019 the Deno authors. All rights reserved. MIT license.
|
|
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
|
import { close } from "./resources.ts";
|
|
|
|
export interface FsEvent {
|
|
kind: "any" | "access" | "create" | "modify" | "remove";
|
|
paths: string[];
|
|
}
|
|
|
|
class FsEvents implements AsyncIterableIterator<FsEvent> {
|
|
readonly rid: number;
|
|
|
|
constructor(paths: string[], options: { recursive: boolean }) {
|
|
const { recursive } = options;
|
|
this.rid = sendSync("op_fs_events_open", { recursive, paths });
|
|
}
|
|
|
|
async next(): Promise<IteratorResult<FsEvent>> {
|
|
return await sendAsync("op_fs_events_poll", {
|
|
rid: this.rid
|
|
});
|
|
}
|
|
|
|
async return(value?: FsEvent): Promise<IteratorResult<FsEvent>> {
|
|
close(this.rid);
|
|
return { value, done: true };
|
|
}
|
|
|
|
[Symbol.asyncIterator](): AsyncIterableIterator<FsEvent> {
|
|
return this;
|
|
}
|
|
}
|
|
|
|
export function fsEvents(
|
|
paths: string | string[],
|
|
options = { recursive: true }
|
|
): AsyncIterableIterator<FsEvent> {
|
|
return new FsEvents(Array.isArray(paths) ? paths : [paths], options);
|
|
}
|