Skip to content

Instantly share code, notes, and snippets.

/**
* Creates a flow WatchEvent from a watchService
*/
fun WatchService.eventFlow() : Flow<List<WatchEvent<out Any>>> = flow {
while (currentCoroutineContext().isActive) {
coroutineScope {
var key: WatchKey? = null
val job = launch {
runInterruptible(Dispatchers.IO) {
key = take()