Watcher
Creates a new instance of the internal `Watcher`.

@name Watcher
@function
@param {String} path The path to the file.
@param {Function} handler A function called when the file changes.
541086
function Watcher(path, handler) {
    this._ = Fs.watch(path, handler);
    this.a_path = Abs(path);
    this.handler = handler;
}
1372319
function Watcher (
  vm,
  expOrFn,
  cb,
  options,
  isRenderWatcher
) {
  this.vm = vm;
  if (isRenderWatcher) {
    vm._watcher = this;
  }
  vm._watchers.push(this);
  // options
  if (options) {
    this.deep = !!options.deep;
    this.user = !!options.user;
    this.lazy = !!options.lazy;
    this.sync = !!options.sync;
    this.before = options.before;
  } else {
    this.deep = this.user = this.lazy = this.sync = false;
  }
  this.cb = cb;
  this.id = ++uid$2; // uid for batching
  this.active = true;
  this.dirty = this.lazy; // for lazy watchers
  this.deps = [];
  this.newDeps = [];
  this.depIds = new _Set();
  this.newDepIds = new _Set();
  this.expression = process.env.NODE_ENV !== 'production'
    ? expOrFn.toString()
    : '';
  // parse expression for getter
  if (typeof expOrFn === 'function') {
    this.getter = expOrFn;
  } else {
    this.getter = parsePath(expOrFn);
    if (!this.getter) {
      this.getter = noop;
      process.env.NODE_ENV !== 'production' && warn(
        "Failed watching path: \"" + expOrFn + "\" " +
        'Watcher only accepts simple dot-delimited paths. ' +
        'For full control, use a function instead.',
        vm
      );
    }
  }
  this.value = this.lazy
    ? undefined
    : this.get();
}
228489
@Deprecated
    public void addWatcher(File file, Listener watcher) {
        addWatcher(file.toPath(), watcher);
    }
460845
public void weakAddWatcher(Path file, Listener watcher) {
        synchronized (mutex) {
            startWatchingInternal(file).add(new WeakReference<>(watcher)::get);
        }
    }
691258
public static WatchMonitor createAll(Path path, Watcher watcher){
		final WatchMonitor watchMonitor = create(path, EVENTS_ALL);
		watchMonitor.setWatcher(watcher);
		return watchMonitor;
	}
528759
public static WatchMonitor create(String path, WatchEvent.Kind<?>... events){
		return create(path, 0, events);
	}
420915
def add_handler(self, path, handler):
        
        self.signatures[path] = self.get_path_signature(path)
        self.handlers[path] = handler
676696
function(event, callback) {
//            if (this instanceof FSObject) {
//                if (event === 'watcher') {
//                    this.__watch_listeners = this.__watch_listeners || 0 + 1;
//                    this.setWatcher();
//                } else if (event === 'fileWatcher') {
//                    this.__watch_file_listeners = this.__watch_file_listeners || 0 + 1;
//                    this.setFileWatcher();
//                }
//            }
            var args = Array.prototype.slice.call(arguments);
            (this.emitter || (this.emitter = new emitter())).on.apply(this, args);
            return this;
        }
269965
public static WatchMonitor create(String path, int maxDepth, WatchEvent.Kind<?>... events){
		return create(Paths.get(path), maxDepth, events);
	}
1139094
function watch(arg_src_dir)
{
	console.info('Watching for change on: ' + arg_src_dir)
	
	const watch_settings = { ignored: /[\/\\]\./, persistent: true }
	var watcher = chokidar.watch(arg_src_dir, watch_settings)
	watcher.on('change', reload_file)
	
	return watcher
}
1140503
public static Runnable watch(Path path, PathEventListener listener) throws IOException {
		return watch(path, listener,
			StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
	}
928945
function handler(isSync) {
    /**
     * lnf
     * Creates or overrides a symlink.
     *
     * @name lnf
     * @function
     * @param {String} target The target file. The path is relative to the `dstpath`.
     * @param {String} dstpath The path where the symlinks will be created or overriden.
     * @param {String} type The symlink type.
     * @param {Function} callback The callback function
     * @return {undefined}
     */
    var lnf = function (target, dstpath, type, callback) {

        if (typeof type === "function") {
            callback = type;
            type = undefined;
        }

        callback = callback || function (err) {
            if (err) { throw err; }
        };

        function res(err) {

            if (err && err.code === "EEXIST") {
                if (isSync) {
                    Fs.unlinkSync(dstpath);
                    lnf(target, dstpath, type, callback);
                } else {
                    Fs.unlink(dstpath, function (err) {
                        if (err) { return callback(err); }
                        lnf(target, dstpath, type, callback);
                    });
                }
                return;
            }

            callback(err);
        }

        if (isSync) {
            try {
                Fs.symlinkSync(target, dstpath, type);
            } catch (err) {
                return res(err);
            }
        } else {
            Fs.symlink(target, dstpath, type, res);
        }
    };
    return lnf;
}
1295440
private void startHandleModifyThread(final WatchEvent<?> event, final Path currentPath) {
		ThreadUtil.execute(new Runnable(){
			@Override
			public void run() {
				ThreadUtil.sleep(delay);
				eventSet.remove(Paths.get(currentPath.toString(), event.context().toString()));
				watcher.onModify(event, currentPath);
			}
		});
	}
1257847
function watch (specs, handler, options) {
  const err = fileOptions.validate(specs)
  if (err) {
    return Promise.reject(err)
  }
  const normalisedSpecs = fileOptions.normalize(specs)
  const events = new EventEmitter()

  // Option resolving
  const opts = options || {}
  const dir = opts.dir || '.'
  const fileReader = opts.fileReader || readAsFile
  const loader = opts.loader || defaultLoader
  const buildConcurrency = opts.concurrency || 1
  const resolveRoot = path.resolve(opts.resolveRoot || process.cwd())

  // State that is maintained by watching for file changes
  const fileInfos = {}
  const affectedFiles = {}
  const affectedFilesInverse = {}

  function linkingLoader (filename, parentFilename) {
    if (parentFilename) {
      const file = path.relative(dir, filename)
      affectedFiles[file] = affectedFiles[file] || new Set()
      affectedFiles[file].add(parentFilename)

      affectedFilesInverse[parentFilename] = affectedFilesInverse[parentFilename] || new Set()
      affectedFilesInverse[parentFilename].add(file)
      watchFile(file)
    }
    return loader(filename, parentFilename)
  }

  function unlinkFile (filename) {
    delete affectedFiles[filename] // the files affected by changing the file `filename`

    // the files that affect the file `filename`
    if (affectedFilesInverse[filename]) {
      affectedFilesInverse[filename].forEach((affectorFilename) => {
        affectedFiles[affectorFilename].delete(filename)
        if (affectedFiles[affectorFilename].size === 0) {
          delete affectedFiles[affectorFilename]
        }
      })

      delete affectedFilesInverse[filename]
    }
  }

  const inlinedWatcher = chokidar.watch([], {cwd: dir})
  inlinedWatcher.on('change', (filename) => {
    const files = Array.from(getSourceFileObjs(filename))
    Promise.all(files.map((fileInfo) => handleFile(fileInfo, {rootCause: 'change', cause: 'change'})))
      .then(() => events.emit('change', filename))
      .catch(handleFileFailure)
  })

  inlinedWatcher.on('unlink', (filename) => {
    const files = Array.from(getSourceFileObjs(filename))
    unlinkFile(filename)
    Promise.all(files.map((fileInfo) => handleFile(fileInfo, {rootCause: 'delete', cause: 'change'})))
      .then(() => events.emit('delete', filename))
      .catch(handleFileFailure)
  })

  function watchFile (filename) {
    inlinedWatcher.add(filename)
  }

  function getSourceFileObjs (filename, collectorSet) {
    const results = collectorSet || new Set()
    if (affectedFiles[filename]) {
      affectedFiles[filename].forEach((affectedFilename) => {
        if (fileInfos[affectedFilename]) {
          results.add(fileInfos[affectedFilename])
        }
        getSourceFileObjs(affectedFilename, results)
      })
    }
    return results
  }

  function workHandler (work) {
    fileInfos[work.fileInfo.src] = work.fileInfo
    return fileReader(work.fileInfo, { loader: linkingLoader, resolveRoot })
      .then(file => handler(undefined, file, work.cause))
      .catch((err) => {
        if (err instanceof ParseError) {
          return handler(err, new File({info: work.fileInfo, content: undefined}), work.cause)
        } else {
          throw err
        }
      })
      .then((res) => work.resolve(res))
      .catch((err) => work.reject(err))
  }

  const workQueue = new WorkQueue(workHandler, {})

  function handleFile (fileInfo, cause) {
    return new Promise((resolve, reject) => {
      workQueue.add({fileInfo: fileInfo, cause: cause, resolve: resolve, reject: reject})
    })
  }

  function handleFileFailure (err) {
    events.emit('error', err)
  }

  function build () {
    return Promise.all(w.files())
      .map((fileInfo) => {
        return handleFile(fileInfo, {rootCause: 'build', cause: 'build'})
      }, {concurrency: buildConcurrency})
  }

  const w = new Watcher(normalisedSpecs, opts)

  w.on('add', (fileInfo) => {
    return handleFile(fileInfo, {rootCause: 'add', cause: 'add'})
      .then(() => events.emit('add', fileInfo.src))
      .catch(handleFileFailure)
  })

  w.on('change', (fileInfo) => {
    return handleFile(fileInfo, {rootCause: 'change', cause: 'change'})
      .then(() => events.emit('change', fileInfo.src))
      .catch(handleFileFailure)
  })

  w.on('remove', (fileInfo) => {
    unlinkFile(fileInfo.src)
    events.emit('delete', fileInfo.src)
  })

  return w._promise.then(() => ({build: build, events: events}))
}
957062
public static WatchMonitor create(Path path, int maxDepth, WatchEvent.Kind<?>... events){
		return new WatchMonitor(path, maxDepth, events);
	}
671070
function setupWatchers(path) {
    // We want to track the watchers now and return if we are already watching this folder
    if (watchingFolders[path]) { return; }

    watchingFolders[path] = fs.watch(path, getWatcher(path + "/"));
    watchingFolders[path].on('error', function() {  verifyWatches(); });
    var fileList = fs.readdirSync(path);
    var stats;
    for (var i = 0; i < fileList.length; i++) {
        try {
            stats = fs.statSync(path + "/" + fileList[i]);
        }
        catch (e) {
            continue;
        }
        if (isWatching(fileList[i])) {
            timeStamps[path + "/" + fileList[i]] = stats.mtime.getTime();
        } else {
            if (stats.isDirectory()) {
                if (fileList[i] === "node_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "tns_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "App_Resources") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                setupWatchers(path + "/" + fileList[i]);
            }
        }
    }
}
1355993
function(handler) {
      var t = this;
      if (t.monitor && t.monitor.isConnected()) {
        setTimeout(function(){handler(t.monitor);},0);
      }
      else {
        t.connectHandlers.push(handler);
      }
    }