-
Notifications
You must be signed in to change notification settings - Fork 59
-
Hey @ALL,
I've a in-memory shared user in my app.
When I subscribe to changes within a Task to it I do not receive the changes:
Task { for await user in $user.publisher.values { print(user) } }
This prints only the initial value but not the changes. The task never finishes nor does it get cancelled as far as I know.
When I subscribe to the changes via Combine it works:
cancellable = $user.publisher.sink { user in print(user) }
What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions
Hi @ALL. It was my own dumbness. I had a guard statement within the for await
loop and in its else block I had a return statement which canceled the loop. 🫣
Replies: 1 comment 7 replies
-
In-memory keys don't implement any kind of subscribing whatsoever currently: https://github.com/pointfreeco/swift-sharing/blob/main/Sources/Sharing/SharedKeys/InMemoryKey.swift#L56-L60
I suppose it would be a welcome addition to the library in a PR?
Beta Was this translation helpful? Give feedback.
All reactions
-
Wild guess, have you checked you don't accidentally overwrite _user
(mind the underscore, as opposed to $user
) with another Shared<...>
? That appears to be a trap for some.
Beta Was this translation helpful? Give feedback.
All reactions
-
No, I don't
Beta Was this translation helpful? Give feedback.
All reactions
-
@pyrtsa that subscription is left empty because there is no external storage system that needs to be subscribed to. But that shouldn’t affect how the publisher works.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Hi @ALL. It was my own dumbness. I had a guard statement within the for await
loop and in its else block I had a return statement which canceled the loop. 🫣
Beta Was this translation helpful? Give feedback.