Skip to content

How to hold objects with lifecycle inside State? #3205

Answered by romanatexn
romanatexn asked this question in Q&A
Discussion options

You must be logged in to vote

Somewhat solved this using this trick, not sure it's the best way tho

case .onTask:

                return .run { @MainActor send in
                    
                    viewModel.create()
                    
                    await withTaskGroup(of: Void.self) { group in

                        group.addTask { @MainActor in
                            do { try await Task.never() } catch {
                                viewModel.clear()
                            }
                        }

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by romanatexn
Comment options

You must be logged in to vote
1 reply
@romanatexn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants