ios – Find out how to Share a Writer between Two Flows

[ad_1]

I’m utilizing one writer to then flip round and do two totally different flows additionally utilizing publishers. How do I am going about sharing the end result from the primary writer to perform each flows beneath.

//1
func getCredentialsPublisher(userInfo: String)-> AnyPublisher<CredentialsResponse, Error>
//A process 1  - create sockets
//B process 2  - retrieve show information from one other service request writer


For Process 1 
//A1
func getSession(token: String) -> AnyPublisher<Session, Error>
//A2
func setupSockets(sessionID: String) -> SocketManager?

For Process 2
//B1
func getExternalObject( token: String) -> AnyPublisher<Object, Error>
//B2
func getViewInfo( Object: struct) -> AnyPublisher<ViewInfo, Error>

I at present do that for the primary process

    let pipeline = self.getCredentialsPublisher(userInfo: "howdy")
        .flatMap { credentialsResponse -> AnyPublisher<Session, Error> in
            // receive worth for token right here...
            let token = "heyho" // or no matter
            return self.getSession(token: token)
        }
        .sink(receiveCompletion: {_ in
            // do one thing if error?
        }, receiveValue: { session in
            // receive worth for session ID right here...
            let sessionID = "yoho" // or no matter
            if let supervisor = self.setupSockets(sessionID: sessionID) {
                // do one thing with the supervisor
            }
        })

How would I am going about doing each duties (A and B ) from the primary writer(getCredentialsPublisher)? one other pipeline?

[ad_2]

Leave a Reply