Skip to content

How to use Combine sinks #244

Answered by sbertix
murataksu740 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @murataksu740,
.
No bugs, your code is just faulty.

First you're not retaining your sink.
You should store(in: &bin) that too instead of discarding the result with _ = .

Your other mistake is that in getUser the publisher only starts streaming when secret changes, not when you actually call it.

init() {
	getUser()
	$current.sink { print($0) }.store(in: &bin)
}
        
func getUser() {
	guard let secret = self.secret.value else { return }
	// Fetch the user.
	Endpoint.user(secret.identifier)
		.unlock(with: secret)
		.session(.instagram)
		.map(\.user)
		.catch { _ in Just(nil) }
		.receive(on: RunLoop.main)
		.assign(to: \.current, on: self)
		.store(in: &bin)
}

You tried to adapt th…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sbertix
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