forked from kscience/kmath
Rework Memory.read method to have more convenient calls with result
This commit is contained in:
parent
27857dffec
commit
1193349b20
@ -83,9 +83,12 @@ interface MemoryReader {
|
||||
/**
|
||||
* Uses the memory for read then releases the reader.
|
||||
*/
|
||||
inline fun Memory.read(block: MemoryReader.() -> Unit) {
|
||||
inline fun <R> Memory.read(block: MemoryReader.() -> R): R {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
reader().apply(block).release()
|
||||
val reader = reader()
|
||||
val result = reader.block()
|
||||
reader.release()
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user