Andrea Giuliano
11/17/2020, 11:59 AMMetricEmitter
where consumers can simply call emitMetric(observation)
. Under the hood this MetricEmitter
will spin up an actor responsible for ingesting those metric observations. From the external consumer of this MetricEmitter
I just want to expose methods such as:
• `metricEmitter.initialize()`: which will spin up the actor and ticker
• `metricEmitter.emitMetric()`: which will ingest the observation
• `metricEmitter.close()`: which will flush remaining metrics and tear down the actor
My problem is that in the initialize()
function, when I try creating the actor, it requires me to provide a CoroutineScope
. If I use coroutineScope { actor<Msg>{... }
this code block will freeze the whole execution since it will complete when the actor terminates. That’s not what I want. I’ve managed to solve the issue by passing a coroutineScope as argument of metricEmitter.initialize(scope: CoroutineScope)
but not sure if this is a smell/antipattern. Any idea how to solve/remodel the solution?Zach Klippenstein (he/him) [MOD]
11/17/2020, 3:46 PMAndrea Giuliano
11/17/2020, 3:47 PMtravis
11/17/2020, 3:53 PMMetricEmitter
via a CoroutineScope
extension function?
fun CoroutineScope.metricEmitter(...)
Possibly implicitly calling your initialize
?Zach Klippenstein (he/him) [MOD]
11/17/2020, 3:59 PM