listen

fun <T : Any> ChangeStreamIterable<T>.listen(executor: ScheduledExecutorService? = null, delay: Long = 500, unit: TimeUnit = TimeUnit.MILLISECONDS, listener: (ChangeStreamDocument<T>) -> Unit): AutoCloseable

Listens change stream in an other thread.

Return

an AutoCloseable that stops the listening (and closes the change stream cursor)

Parameters

executor

the executor service for the thread instantiation - if null (the default), a single (daemon) thread executor is created and shut down when the change stream cursor is closed

delay

the delay the executor is waiting before submitting the task

unit

the unit of the delay

listener

to listen changes