Last active
September 3, 2018 07:03
-
-
Save SergeyPetrachkov/ad5c4a9434828aba5ad27e456f939837 to your computer and use it in GitHub Desktop.
remote chats provider for medium article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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