Kotlin API wrapper for Java's WatchService powered with Channels and Coroutines. a.k.a. KWatchChannel
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")
}
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