added a helper method to make it really easy to create a Runnable from a function

This commit is contained in:
James Strachan
2012-04-05 11:56:28 +01:00
parent 0a7a168e0d
commit fefcd1e5df
@@ -43,10 +43,20 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo
return thread
}
/**
* Executes the given block on the [[Executor]]
*/
public inline fun Executor.execute(action: ()->Unit) {
execute(object: Runnable{
execute(runnable(action))
}
/**
* A helper method for creating a [[Runnable]] from a block
*/
public inline fun runnable(action: ()-> Unit): Runnable {
return object: Runnable {
public override fun run() {
action()
}
})
}
}