From 1b6f8318750d319d689f7eeef9e7e1f2e56b94a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 8 Mar 2020 13:09:22 +0100 Subject: reorg: move JS ops implementations to cli/js/ops/, part 1 (#4264) 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 --- cli/js/ops/fs_events.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cli/js/ops/fs_events.ts (limited to 'cli/js/ops/fs_events.ts') diff --git a/cli/js/ops/fs_events.ts b/cli/js/ops/fs_events.ts new file mode 100644 index 000000000..09e82c515 --- /dev/null +++ b/cli/js/ops/fs_events.ts @@ -0,0 +1,39 @@ +// 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 { + readonly rid: number; + + constructor(paths: string[], options: { recursive: boolean }) { + const { recursive } = options; + this.rid = sendSync("op_fs_events_open", { recursive, paths }); + } + + async next(): Promise> { + return await sendAsync("op_fs_events_poll", { + rid: this.rid + }); + } + + async return(value?: FsEvent): Promise> { + close(this.rid); + return { value, done: true }; + } + + [Symbol.asyncIterator](): AsyncIterableIterator { + return this; + } +} + +export function fsEvents( + paths: string | string[], + options = { recursive: true } +): AsyncIterableIterator { + return new FsEvents(Array.isArray(paths) ? paths : [paths], options); +} -- cgit v1.2.3