run first lists all items and get the resource version at the moment of call, and then use the
resource version to watch.
772913
public void run() {
    try {
      log.info("{}#Start listing and watching...", apiTypeClass);

      ApiListType list = listerWatcher.list(new CallGeneratorParams(Boolean.FALSE, null, null));

      V1ListMeta listMeta = Reflect.listMetadata(list);
      String resourceVersion = listMeta.getResourceVersion();
      List<ApiType> items = Reflect.getItems(list);

      if (log.isDebugEnabled()) {
        log.debug("{}#Extract resourceVersion {} list meta", apiTypeClass, resourceVersion);
      }
      this.syncWith(items, resourceVersion);
      this.lastSyncResourceVersion = resourceVersion;

      if (log.isDebugEnabled()) {
        log.debug("{}#Start watching with {}...", apiTypeClass, lastSyncResourceVersion);
      }
      while (true) {
        if (!isActive.get()) {
          if (watch != null) {
            watch.close();
            return;
          }
        }

        try {
          if (log.isDebugEnabled()) {
            log.debug(
                "{}#Start watch with resource version {}", apiTypeClass, lastSyncResourceVersion);
          }
          watch =
              listerWatcher.watch(
                  new CallGeneratorParams(
                      Boolean.TRUE,
                      lastSyncResourceVersion,
                      Long.valueOf(Duration.ofMinutes(5).toMillis()).intValue()));
          watchHandler(watch);
        } catch (Throwable t) {
          log.info("{}#Watch connection get exception {}", apiTypeClass, t.getMessage());
          Throwable cause = t.getCause();
          // If this is "connection refused" error, it means that most likely apiserver is not
          // responsive.
          // It doesn't make sense to re-list all objects because most likely we will be able to
          // restart
          // watch where we ended.
          // If that's the case wait and resend watch request.
          if (cause != null && (cause instanceof ConnectException)) {
            log.info("{}#Watch get connect exception, retry watch", apiTypeClass);
            Thread.sleep(1000L);
            continue;
          }
          if ((t instanceof RuntimeException)
              && t.getMessage().contains("IO Exception during hasNext")) {
            log.info("{}#Read timeout retry list and watch", apiTypeClass);
            return;
          }
          log.error("{}#Watch failed as {} unexpected", apiTypeClass, t.getMessage(), t);
          return;
        } finally {
          if (watch != null) {
            watch.close();
            watch = null;
          }
        }
      }
    } catch (Throwable t) {
      log.error("{}#Failed to list-watch: {}", apiTypeClass, t);
    }
  }
964754
async def _watch(self):
        

        file_name = os.path.basename(self._file_path)
        logger.info(
            'Watching %s "%s"',
            self.THING,
            self._file_path,
        )

        while self._running:
            evt = await self._watcher.get_event()

            if evt.name == file_name:
                await self._load()
                logger.info(
                    'Reloading changed %s from "%s"',
                    self.THING,
                    self._file_path
                )
1299479
def run(self):
        """"""
        while True:
            try:
                cursor = JSON_CLIENT.json_client['local']['oplog.rs'].find(
                    {'ts': {'$gt': self.last_timestamp}})
            except TypeError:
                # filesystem, so .json_client is a bool and not iterable
                pass
            else:
                # http://stackoverflow.com/questions/30401063/pymongo-tailing-oplog
                cursor.add_option(2)  # tailable
                cursor.add_option(8)  # oplog_replay
                cursor.add_option(32)  # await data
                self._retry()
                for doc in cursor:
                    self.last_timestamp = doc['ts']
                    if doc['ns'] in self.receivers:
                        self._run_namespace(doc)
            time.sleep(1)
1343471
def run(self, url):
        """"""
        url = self.process_url(url)
        if not url:
            return
        response = self.make_request(self.http, url)
        selector = self.process_response(response)
        entities = []
        for root in self.get_roots(selector):
            entity = self.entity(root)
            entity = self.process_entity(entity)
            if entity:
                entities.append(entity)
        return EntityList(*entities)
1055639
def my_version():
    """"""
    if os.path.exists(resource_filename(__name__, 'version')):
        return resource_string(__name__, 'version')

    return open(os.path.join(os.path.dirname(__file__),
                             "..", "version")).read()
347860
def run(self):
        """"""
        # Catch all possible exceptions raised by the running thread
        # and let parent process know about it.
        try:
            self._run()
        except Exception:  # pylint: disable=broad-except
            self.action.put(
                ServiceCheckDiedError(self.name, traceback.format_exc())
            )
516271
def run(self, resources):
        

        hwman = resources['connection']

        updater = hwman.hwman.app(name='device_updater')
        updater.run_script(self._script, no_reboot=self._no_reboot)
1352990
def _run(self):
        
        try:
            start_time = time.time()

            # Collect Data
            self.collect()

            end_time = time.time()
            collector_time = int((end_time - start_time) * 1000)

            self.log.debug('Collection took %s ms', collector_time)

            if 'measure_collector_time' in self.config:
                if self.config['measure_collector_time']:
                    metric_name = 'collector_time_ms'
                    metric_value = collector_time
                    self.publish(metric_name, metric_value)
        finally:
            # After collector run, invoke a flush
            # method on each handler.
            for handler in self.handlers:
                handler._flush()
506286
def run_recursively(monitor, directory, *flags, &block)
      result = watch_and_run(monitor, 1, true, directory, *flags, &block)
      result.changes[0].directory = result.directory
      result.changes[0]
    end
1372623
def _version_view(self):
        
        version_json = self._version_callback(self.version_path)
        if version_json is None:
            return 'version.json not found', 404
        else:
            return jsonify(version_json)
32042
def run(monitor, directory, *flags, &block)
      result = watch_and_run(monitor, 1, false, directory, *flags, &block)
      result.changes[0].directory = result.directory
      result.changes[0]
    end
567916
def _run_first(self, source_file):
        """"""

        self.reset()
        self.current_encoding = self.default_encoding
        encoding = None
        try:
            encoding = self._detect_encoding(source_file)
            content = self.filter(source_file, encoding)
        except UnicodeDecodeError:
            if not encoding or encoding != self.default_encoding:
                content = self.filter(source_file, self.default_encoding)
            else:
                raise
        return content
1351248
function watch(done) {
  var mainWatcher = gulp.watch([
    'src/**/*.js',
    'modules/**/*.js',
    'test/spec/**/*.js',
    '!test/spec/loaders/**/*.js'
  ]);
  var loaderWatcher = gulp.watch([
    'loaders/**/*.js',
    'test/spec/loaders/**/*.js'
  ]);

  connect.server({
    https: argv.https,
    port: port,
    root: './',
    livereload: true
  });

  mainWatcher.on('all', gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test)));
  loaderWatcher.on('all', gulp.series(lint));
  done();
}
1047873
def run(self):
        
        self.pre_run()
        first = True
        while self.runnable:
            self.pre_call_message()

            if first:
                self.pre_first_call_message()
            
            message, payload = self.listener.get()
            getattr(self, message)(payload)

            if first:
                first = False
                self.post_first_call_message()
                
            self.post_call_message()

        self.post_run()
998506
def resource_collection_show(self, id, **kwargs):
        ""
        api_path = "/api/v2/resource_collections/{id}.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
940113
async def first(self):
        
        if self._metadata is None:
            self._non_result()
        try:
            return (await self.fetchone())
        finally:
            await self.close()
302134
public function watch($resource)
    {
        if (!$this->files->exists($resource)) {
            throw new RuntimeException('Resource must exist before you can watch it.');
        } elseif ($this->files->isDirectory($resource)) {
            $resource = new DirectoryResource(new SplFileInfo($resource), $this->files);

            $resource->setupDirectory();
        } else {
            $resource = new FileResource(new SplFileInfo($resource), $this->files);
        }

        // The listener gives users the ability to bind listeners on the events
        // created when watching a file or directory. We'll give the listener
        // to the tracker so the tracker can fire any bound listeners.
        $listener = new Listener();

        $this->tracker->register($resource, $listener);

        return $listener;
    }