override fun invokeOnDispose()

in hot-reload-devtools/src/main/kotlin/org/jetbrains/compose/devtools/RecompilerContextImpl.kt [32:53]


    override fun invokeOnDispose(action: () -> Unit): Disposable {
        val wrapper = { action() }

        state.update { current ->
            when (current) {
                is State.Disposed -> {
                    action()
                    current
                }
                is State.Active -> State.Active(current.actions + wrapper)
            }
        }

        return Disposable {
            state.update { current ->
                when (current) {
                    is State.Disposed -> current
                    is State.Active -> current.copy(actions = current.actions - wrapper)
                }
            }
        }
    }