Giter Site home page Giter Site logo

watchservice-ktx's Introduction

watchservice-ktx

Kotlin API wrapper for Java's WatchService powered with Channels and Coroutines. a.k.a. KWatchChannel

Getting started

This repository is hosted via jitpack since it's by far the easiest delivery method while also being pretty transparent to the developer.

Make sure you have added jitpack to the list of your repositories:

maven("https://jitpack.io")

Then simply add the watchservice-ktx dependency

dependencies {
  compile("com.github.vishna:watchservice-ktx:master-SNAPSHOT")
}

Example usage

val currentDirectory  = File(System.getProperty("user.dir"))

val watchChannel = currentDirectory.asWatchChannel()

launch {
  watchChannel.consumeEach { event ->
    // do something with event
  }
}

// once you no longer need this channel, make sure you close it
watchChannel.close()

For more documentation on API see watchservice.kt or check out the medium article

watchservice-ktx's People

Contributors

vishna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

watchservice-ktx's Issues

take() blocks indefinitely

It looks like the core loop is using up a lot more CPU than it should due to a busy-wait, correct? Would it be better to sleep between iterations?

Btw, thanks for the blog post and WatchService example! Even though I don't know Kotlin, I found it easy to follow.

Handling of large file being written to the watched folder

When large files are being written into a watched folder over some network, there is a possiblity that a partial file is received for processing in the consumer.

There are multiple ways to handle this, but the easiest to ensure that the file's modified timestamp does not change for more than n seconds (e.g. 5 secs) and then send the event over the channel for processing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.