Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use effects to denote scope of work #3

Open
JakeWharton opened this issue Nov 20, 2020 · 3 comments
Open

Use effects to denote scope of work #3

JakeWharton opened this issue Nov 20, 2020 · 3 comments

Comments

@JakeWharton
Copy link
Owner

Currently we build our own coroutine scope to encapsulate all of the work required to render. When this scope ends, rendering ends and the program exits cleanly (modulo internal nonsense to make this work).

Ideally effects inside the composition are used to scope the composition instead. Compose internals currently prevent this, which is tracked as https://issuetracker.google.com/issues/169425431.

@JakeWharton
Copy link
Owner Author

JakeWharton commented Nov 21, 2020

Today:

fun main() = runMosaic {
  val countValue = mutableStateOf(0)

  setContent {
    val count by remember { countValue }
    Text("The count is: $count")
  }

  for (i in 1..20) {
    delay(250)
    countValue.value = i
  }
}

Tomorrow:

fun main() = runMosaic {
  val count by remember { mutableStateOf(0) }
  Text("The count is: $count")

  LaunchedEffect(null) {
    for (i in 1..20) {
      delay(250)
      count++
    }
  }
}

@JakeWharton
Copy link
Owner Author

I was doing some Compose UI for Desktop recently, and it seems like they support this internally. Need to investigate.

@m-sasha
Copy link

m-sasha commented Apr 12, 2024

I think what you need is something like FlushCoroutineDispatcher from Compose Multiplatform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants