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

Helpful tip for childSlot #712

Closed
longqingzhao opened this issue May 9, 2024 · 6 comments · Fixed by #716
Closed

Helpful tip for childSlot #712

longqingzhao opened this issue May 9, 2024 · 6 comments · Fixed by #716
Labels
enhancement New feature or request

Comments

@longqingzhao
Copy link

longqingzhao commented May 9, 2024

I have an idea for this project.
when call childSlot in Dispatcher.IO before。check current Thread==''main''
This is helpful to resolve bug faster!

@arkivanov
Copy link
Owner

There are already main thread checks implemented. Could you please elaborate?

@longqingzhao
Copy link
Author

longqingzhao commented May 10, 2024

You are right. But when I initialize a childStack in other thread unconsciously.

For example:
IDmk2WbfzB

1.When I call dialogNavigation.navigate { state }. It will be initialized in io coroutineScope and throw error about check main thread
igk8vciETU

2.When I call dialogNavigation.navigate { state }. It will be initialized in UI coroutineScope and my app closed with nothing error.
vooVcedJ5L
IwvEqusnTe

When I initialize childStack by these error way,I need to analysis source code and debug.

If check main thread for here,I can know the cause first. It's friendly for some developer.

20240510-085507

@arkivanov
Copy link
Owner

arkivanov commented May 10, 2024

Perhaps, we could an additional main thread check.

Btw, your first code snippet has a mistake. Please don't use get() = for navigation properties, just assign the value directly val state: Value<ChildSlot<...>> = childSlot(...).

@arkivanov arkivanov added the enhancement New feature or request label May 10, 2024
@arkivanov
Copy link
Owner

Sorry but I still don't see where is the issue in your case. The case #1 has the main thread check already and prints the error in the logs because of the background thread. The case #2 has the main thread check as well and should work correctly because of the main thread.

@arkivanov arkivanov added the investigate Something might be broken and needs to be investigated label May 10, 2024
@longqingzhao
Copy link
Author

In case #1, I indeed have a main thread check and an error message is thrown. However, the error message did not specifically mention that val state: Value<ChildSlot<...>> = childSlot(...) cannot be used on a background thread.
I spent a long time searching for the issue and trying out various solutions before realizing that my val state: Value<ChildSlot<...>> = childSlot(...) was being executed on a background thread.

The problem is that while there is a main thread check, it does not explicitly indicate that childSlot must be run on the main thread in error.

Therefore, I suggest that a main thread check should be performed inside the childSlot method and an exception should be thrown accordingly. This would be very user-friendly.

@arkivanov
Copy link
Owner

Ok, so the actual issue is because the property is accessed on a background thread. It makes sense to add the additional check. Thanks for raising.

@arkivanov arkivanov removed the investigate Something might be broken and needs to be investigated label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants