Replies: 6 comments
-
this is likely because you're not receiving the effect on the main queue. try changing your code to:
|
Beta Was this translation helpful? Give feedback.
-
You're right, that fixed it. So does |
Beta Was this translation helpful? Give feedback.
-
Everything is on the main thread, as you can check with a few assertions. The issue is elsewhere. I think that's because cancellable effects are behaving like a deferred This is a gotcha and there's maybe room for improvement with the API. |
Beta Was this translation helpful? Give feedback.
-
Is this about the Deffered used in cancellable? |
Beta Was this translation helpful? Give feedback.
-
So the repository effect is being wrapped inside a Deferred when marked cancellable. But I still don't really understand why the initial value is being sent before the Deferred is being subscribed to now, since I only trigger the initial fetch after a subscription is received. Is it because the wrapped effect (the repo in this case) is being subscribed to inside of the Deferred? But shouldn't this not actually run until the Deferred itself is subscribed to? |
Beta Was this translation helpful? Give feedback.
-
The The If its not an issue on send from non-main. Thinking.. There should probably be a debug-publisher which tests whether he receives on the main thread and if not crashes or prints a warning or sth. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Marking a long-running
Effect
that immediately emits a value after being subscribed to causes that value to be lost.To Reproduce
CancellableIssue.zip
The attached project has a
Repository
effect that wraps anNSFetchedResultsController
. The view displays the count of items in Core Data, and has a button to add another to the database. When you first launch the app, you'll see "0 names". In theonAppear
on the view, we trigger the start of the repo. If you click the button a few times, you'll see the number increment. Do this a few times and then relaunch the app. When the view appears, you'll see it immediately says "x names", where x is the number of times you clicked the button in the last run (i.e. the number of items in Core Data).Now go to the reducer in Core.swift and uncomment the
cancellable
line:Re-run the app with this change, and when the view loads, you'll see "0 names" again. Only after clicking the button again will this update to "x+1 names". The initial value emitted by the repo was lost after making it cancellable.
Expected behavior
Making a long-running
Effect
cancellable should not cause the initial immediate value emitted to be lost.Screenshots
https://user-images.githubusercontent.com/2407424/113312889-b90a8e00-92d8-11eb-8af3-59f7057fae33.mp4
Environment
Beta Was this translation helpful? Give feedback.
All reactions