this is ported from java. in the original code f...
# announcements
j
this is ported from java. in the original code future[0] appears to be a hack to reach between scopes. is there more than one way to smooth over the array of one hack?
Copy code
private fun scheduleTask(address: MemberAddress, command: Runnable, delay: Int, units: TimeUnit) {
        waiting.computeIfAbsent(address) { a: MemberAddress? ->
              lateinit  var future:  ScheduledFuture<*> 

            executor.schedule(loggingExceptions(Runnable {
                waiting.remove(address, future )
                command.run()
            }), delay.toLong(), TimeUnit.MILLISECONDS) .also { future=it }
        }
    }
d
In Kotlin you can write to `var`s from the "outer scope" just fine, Kotlin will compile to a boxed reference (equivalent to the array of one hack) automatically.
This compiles (and works) fine in Kotlin:
Copy code
var x: String = "hello"
    val runnable = Runnable {
        x += " world"
    }
j
the runnable inside the Futue is referring to the result of schedulling the Runnable.
.also{future=it}
appears to be doing the array of one hack, which seems like I'm forgetting a cleaner trick