package Ġcom . l hw dev . self Test Macro . utils Ċ Ċ import Ġandroidx . compose . runtime .* Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġandroidx . lifecycle . Lifecycle Event Observer Ċ import Ġkotlinx . coroutines . flow . collect Latest Ċ import Ġkotlinx . coroutines . isActive Ċ import Ġkotlin . coroutines . coroutine Context ĊĊ Ċ val ĠLocal Lifecycle State : ĠPro vid able Composition Local < State < Lifecycle . State >> Ġ= Ċ ĉ composition Local Of Ġ{ Ġerror (" not Ġprovided ") Ġ} ĊĊ Ċ @ Composable Ċ fun ĠLifecycle . observe As State (): ĠState < Lifecycle . State > Ġ{ Ċ ĉ val Ġstate Ġ= Ġremember Ġ{ Ġmutable State Of ( currentState ) Ġ} Ċ ĉ Disposable Effect ( this ) Ġ{ Ċĉ ĉ val Ġobserver Ġ= ĠLifecycle Event Observer Ġ{ Ġ_, Ġevent Ġ-> Ċĉĉ ĉ state . value Ġ= Ġevent . target State Ċĉ ĉ } Ċĉ ĉ add Observer ( observer ) Ċĉ ĉ on Dispose Ġ{ Ċĉĉ ĉ remove Observer ( observer ) Ċĉ ĉ } Ċ ĉ } Ċ ĉ return Ġstate Ċ } ĊĊ Ċ suspend Ġfun ĠState < Lifecycle . State >. repeat While ( at Least : ĠLifecycle . State , Ġblock : Ġsuspend Ġ() Ġ-> ĠUnit ) Ġ{ Ċ ĉ snapshot Flow Ġ{ Ġvalue Ġ}. collect Latest Ġ{ Ċĉ ĉ if ( it Ġ>= Ġat Least ) Ġwhile ( coroutine Context . isActive ) Ġ{ Ċĉĉ ĉ block () Ċĉ ĉ } Ċ ĉ } Ċ } Ċ