Rework Memory.read method to have more convenient calls with result

This commit is contained in:
Iaroslav Postovalov 2020-08-27 18:21:30 +07:00
parent 27857dffec
commit 1193349b20
No known key found for this signature in database
GPG Key ID: 70D5F4DCB0972F1B

View File

@ -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
}
/**