Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
I’ve three capabilities that must be referred to as serially. Two of them are publishers. The third one creates sockets. After calling the primary perform(request writer) I must then flip round and name different requests.
I’m having a tough time with the syntax for chaining and mapping the result of 1 request to the opposite.
My calls so as are
//1
func getCredentialsPublisher(userInfo: String)-> AnyPublisher<CredentialsResponse, Error>
//2
func getSession(token: String) -> AnyPublisher<Session, Error>
//3
func setupSockets(sessionID: String) -> SocketManager?
The getCredentialsPublisher compiles and returns the anticipated data.
The difficulty I’m having is attempting to transform getSession writer to return a SocketManager.
func startSession(uniqueId: String) -> AnyPublisher<SocketManager?, By no means>
return getSession(token: uniqueId)
.flatMap { response in
let socket = self.setupSockets(sessionID: response.id)
return Simply(socket)
.catch { _ in
Simply(nil)
}
}
.eraseToAnyPublisher()
}
this provides me a “Can’t convert return expression of sort ‘AnyPublisher<P.Output, Error>’ to return sort ‘AnyPublisher<SocketManager?, By no means>'”
Any concepts why?
since sockets are created as soon as, is it okay to have “By no means” for the failure?
In my viewModel, I take advantage of it like this
var credentialsSubscriber: AnyCancellable?
var startSessionSubscriber: AnyCancellable?
credentialsSubscriber =.getCredentialsPublisher(userInfo: object)
.sink { lead to
print("end result from get credentials: (end result).")
} receiveValue: { response in
//A. begin sockets
startSessionSubscriber = startSession(uniqueId: response.id)
.sink( receiveValue: { socket in
self.socketManager = socket
}
//B. do one thing else that must be achieved when credentials are acquired.
}
is that this the correct technique to chain calls 1 and a pair of? Do I would like totally different subscribers for A. and B.?
[ad_2]