I guess notably it suspends instead of blocking by virtue of the mutex use.
👍 1
d
Derek Berner
08/06/2019, 7:28 PM
Yeah that mutex is exactly what I'm looking for
Derek Berner
08/06/2019, 7:28 PM
blocking within
IO
seems bad, where avoidable
y
yschimke
08/07/2019, 6:05 AM
That's a nice library function. Would it be easy/possible to adapt that to work for any shape function? e.g. two args instead of zero args?
yschimke
08/07/2019, 6:08 AM
I hope at some point there is a memoize tied to coroutine scopes. Provided by the standard libraries. Tying to a request, or application seems very natural.
a
Antanas A.
08/07/2019, 7:13 AM
My implementation:
Copy code
suspend inline fun <R> (suspend () -> R).memoize(): suspend () -> R {
val Undef = object {}
var value: Any? = Undef
return suspend {
if (value === Undef) value = this() as Any?
value as R
}
}