Giter VIP home page Giter VIP logo

Comments (5)

zsmb13 avatar zsmb13 commented on September 22, 2024

Looking at the impl of eventFlow:

public val Lifecycle.eventFlow: Flow<Lifecycle.Event>
    get() = callbackFlow {
        val observer = LifecycleEventObserver { _, event ->
            trySend(event)
        }.also { addObserver(it) }

        awaitClose { removeObserver(observer) }
    }.flowOn(Dispatchers.Main.immediate)

Apparently it uses Dispatchers.Main, which is not available if you don't add coroutines-swing to the project explicitly. Adding this dependency fixes the issue:

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.1")

from compose-multiplatform.

SebastianAigner avatar SebastianAigner commented on September 22, 2024

Very strange that I'm seeing no indication (warning, error, log output) indicating this.

from compose-multiplatform.

MatkovIvan avatar MatkovIvan commented on September 22, 2024

It's expected because kotlinx-coroutines-swing is optional. I'll check why a warning message is missed + make sure that it's desired in docs

from compose-multiplatform.

MatkovIvan avatar MatkovIvan commented on September 22, 2024

Rechecked what's going on here.

Compose for Desktop doesn't emit lifecycle events

It does. Even without this extra dependency. You can receive it via:

lifecycle.addObserver(object : LifecycleEventObserver {
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        println("New Event: $event")
    }

})

Very strange that I'm seeing no indication (warning, error, log output) indicating this.

It looks like behavior of flowOn function + missed Dispatchers.Main. Example:

flowOf(1, 2, 3)
    .flowOn(Dispatchers.Main.immediate)
    .collect {
        println("collect: $it")
    }

Will print nothing and hang on collect function without any exceptions. I guess it is out of the scope of Compose Multiplatfrom repo, but maybe worth creating YT issue for coroutines library.

from compose-multiplatform.

okushnikov avatar okushnikov commented on September 22, 2024

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.