Add support for JSON-RPC batching (#67)
* Update StdioTransport documentation comments to indicate support for JSON-RPC batches * Add server support for JSON-RPC batching * Add client support for JSON-RPC batching * Fix bug that caused error messages to be wrapped unnecessarily
This commit is contained in:
parent
2a978d175e
commit
82f4fd29b3
1 changed files with 630 additions and 37 deletions
|
|
@ -80,8 +80,7 @@ actor MockTransport: Transport {
|
|||
shouldFailSend = shouldFail
|
||||
}
|
||||
|
||||
func queue<M: Method>(request: Request<M>) throws {
|
||||
let data = try encoder.encode(request)
|
||||
func queue(data: Data) {
|
||||
if let continuation = dataStreamContinuation {
|
||||
continuation.yield(data)
|
||||
} else {
|
||||
|
|
@ -89,14 +88,24 @@ actor MockTransport: Transport {
|
|||
}
|
||||
}
|
||||
|
||||
func queue<M: Method>(request: Request<M>) throws {
|
||||
queue(data: try encoder.encode(request))
|
||||
}
|
||||
|
||||
func queue<M: Method>(response: Response<M>) throws {
|
||||
let data = try encoder.encode(response)
|
||||
dataToReceive.append(data)
|
||||
queue(data: try encoder.encode(response))
|
||||
}
|
||||
|
||||
func queue<N: Notification>(notification: Message<N>) throws {
|
||||
let data = try encoder.encode(notification)
|
||||
dataToReceive.append(data)
|
||||
queue(data: try encoder.encode(notification))
|
||||
}
|
||||
|
||||
func queue(batch requests: [AnyRequest]) throws {
|
||||
queue(data: try encoder.encode(requests))
|
||||
}
|
||||
|
||||
func queue(batch responses: [AnyResponse]) throws {
|
||||
queue(data: try encoder.encode(responses))
|
||||
}
|
||||
|
||||
func decodeLastSentMessage<T: Decodable>() -> T? {
|
||||
|
|
|
|||
Loading…
Reference in a new issue