summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkSwift/SDLManagerSwift.swift
blob: 38a2b677b81b3ed0c68a752af02a83c46829a053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
//  SDLManagerSwift.swift
//  SmartDeviceLinkSwift
//
//  Created by George Miller on 8/8/22.
//  Copyright © 2022 smartdevicelink. All rights reserved.
//

import Foundation
import SmartDeviceLink

public class SDLManagerSwift {
    @available(iOS 13.0.0, *)
    //pass in the request.
    //instead of passing in the response handler, the response handler is done in the continueation, which is called when the internal send returns
    public class func sendRPCRequest(_ request: SDLRPCRequest, using manager: SDLManager) async throws -> (SDLRPCRequest, SDLRPCResponse){
        try await withCheckedThrowingContinuation{ continuation in
            manager.send(request: request) {req, res, err in
                if let error = err {
                    continuation.resume(throwing: error)
                } else if let request = req, let response = res {
                    continuation.resume(returning: (request, response))
                } else {
                    continuation.resume(throwing: SendError.unknownError)
                }
            }
        }
    }
    
    
    
    enum SendError: Error {
        case unknownError
    }
    
}