could someone proof-read this? it seems to work, I...
# codereview
d
could someone proof-read this? it seems to work, I just want to make sure that I understand
CompletableFuture
correctly if I hammer (just from a single thread)
asyncDumpReport()
then am I correct to assume that there is no chance of
dumpReport()
firing until the previous call to
dumpReport()
has completed?
Copy code
`
    /**
     * calls [dumpReport] asynchronously, _if there is not currently such a call in progress_
     */
    private fun asyncDumpReport() {
        val p = promise
        if (p == null || p.getNow(false))
            promise = CompletableFuture.supplyAsync {
                try {
                    dumpReport()
                } finally {}
                true
            }
    }
    private var promise: CompletableFuture<Boolean>? = null
`
a
Yes, if you call
asyncDumpReport
while another dump is still running, it will just skip the dumping-part
d
great, thanks
t
The thread safety seems dubious to me me, what if two threads call at the same time and both check the if statement before any of them have set the promise? Then you have two dump reports running at the same time. Or if promise is assigned to while another thread is between
val p =...
and the if? Since you not using the result of CompletableFuture you're could instead of use the thread safe functions from AtomicBoolean for the example