Skip to content

Remove redundant use of coroutineScope inside of LaunchedEffect. #5811

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Sagar0-0
Copy link
Contributor

@Sagar0-0 Sagar0-0 commented Jun 5, 2025

🎯 Goal

Avoid unnecessary coroutine scope creation inside a LaunchedEffect block and simplify the coroutine launch logic in the PinnedMessagesScreen.

  • This improves code readability and adheres to best practices in Compose.
  • Avoid manually launching nested coroutines when the outer scope already provides the structured, lifecycle-safe coroutine.
  • Creating a CoroutineScope just to immediately launch one job inside another coroutine (LaunchedEffect) is unnecessary indirection and adds no value in our case.
  • Keep coroutine usage minimal and clear.

🛠 Implementation details

Replaced the use of rememberCoroutineScope() within LaunchedEffect with a direct suspend call to collect from viewModel.errorEvents. Since LaunchedEffect already provides a lifecycle-aware coroutine scope, creating an additional scope was redundant.

🧪 Testing

This change is covered by existing UI behavior. To verify:

  • Trigger a message error in PinnedMessagesScreen.
  • Confirm that the Toast still shows the error message correctly.

No additional testing patch is required.

☑️Contributor Checklist

General

  • I have signed the Stream CLA (required)
  • Assigned a person / code owner group (required)
  • Thread with the PR link started in a respective Slack channel (#android-chat-core or #android-chat-ui) (required)
  • PR is linked to the GitHub issue it resolves

Code & documentation

  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (KDocs, docusaurus, tutorial)

☑️Reviewer Checklist

  • UI Components sample runs & works
  • Compose sample runs & works
  • UI Changes correct (before & after images)
  • Bugs validated (bugfixes)
  • New feature tested and works
  • Release notes and docs clearly describe changes
  • All code we touched has new or updated KDocs

🎉 GIF

FreshFromTheBathCuteDogGIF

@Sagar0-0 Sagar0-0 requested a review from a team as a code owner June 5, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant