Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.18 KB

README.md

File metadata and controls

40 lines (27 loc) · 1.18 KB

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