Skip to content

Instantly share code, notes, and snippets.

@SergeyPetrachkov
Last active September 3, 2018 07:03
Show Gist options
  • Select an option

  • Save SergeyPetrachkov/ad5c4a9434828aba5ad27e456f939837 to your computer and use it in GitHub Desktop.

Select an option

Save SergeyPetrachkov/ad5c4a9434828aba5ad27e456f939837 to your computer and use it in GitHub Desktop.
remote chats provider for medium article
class RemoteChatsProvider: ChatsProvider {
func getChats(request: GetConversationsRequest) throws -> [Message] {
var items: [MessageDto] = []
var outputError: Error? = nil
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
CompanyMessagesAPI.companyMessagesGetConversations(request: request, completion: { (successfulResponse, error) in
do {
items = try SwaggerApiResponseHandler.unwrapResponse((successfulResponse, error))
dispatchGroup.leave()
} catch let error {
outputError = error
dispatchGroup.leave()
}
})
_ = dispatchGroup.wait(timeout: .distantFuture)
if let error = outputError {
throw error
}
return items.map({ Message(wsInstance: $0) }).compactMap({$0})
}
/// etc ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment