     }
   }
 
-  /// Send a message. Nonblocking.
-  internal func send(_ response: Echo_EchoResponse, completion: @escaping ()->()) throws {
+  func send(_ response: Echo_EchoResponse, completion: @escaping ()->()) throws {
     try handler.sendResponse(message:response.serializedData()) {completion()}
   }
 
-  /// Close a connection. Blocks until the connection is closed.
-  internal func close() throws {
+  func close() throws {
     let sem = DispatchSemaphore(value: 0)
     try self.handler.sendStatus(statusCode:self.statusCode,
                                 statusMessage:self.statusMessage,

    return requestMessage!
  }

  /// Send a response and close the connection.
  internal func sendAndClose(_ response: Echo_EchoResponse) throws {
    try self.handler.sendResponse(message:response.serializedData(),
                                  statusCode:self.statusCode,
                                  statusMessage:self.statusMessage,

    }
  }

  func send(_ message:Echo_EchoRequest, errorHandler:@escaping (Error)->()) throws {
    let messageData = try message.serializedData()
    try call.sendMessage(data:messageData, errorHandler:errorHandler)
  }

  func closeSend(completion:@escaping ()->()) throws {
    try call.close() {
      completion()
    }
  }

  func cancel() {
    call.cancel()
  }
}



/// Instantiate Echo_EchoServiceImpl, then call methods of this protocol to make API calls.
internal protocol Echo_EchoService {
  var channel: Channel { get }

  /// This metadata will be sent with all requests.
  var metadata: Metadata { get }

  /// This property allows the service host name to be overridden.
  /// For example, it can be used to make calls to "localhost:8080"
  /// appear to be to "example.com".
  var host : String { get }

  /// This property allows the service timeout to be overridden.
  var timeout : TimeInterval { get }
  
  /// Synchronous. Unary.
  func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse
  /// Asynchronous. Unary.
  func get(_ request: Echo_EchoRequest,
                  completion: @escaping (Echo_EchoResponse?, CallResult)->()) throws -> Echo_EchoGetCall

  /// Asynchronous. Server-streaming.
  /// Send the initial message.
  /// Use methods on the returned object to get streamed responses.
  func expand(_ request: Echo_EchoRequest, completion: @escaping (CallResult)->())
    throws -> Echo_EchoExpandCall

  /// Asynchronous. Client-streaming.
  /// Use methods on the returned object to stream messages and
  /// to close the connection and wait for a final response.
  func collect(completion: @escaping (CallResult)->())
    throws -> Echo_EchoCollectCall

  /// Asynchronous. Bidirectional-streaming.
  /// Use methods on the returned object to stream messages,
  /// to wait for replies, and to close the connection.
  func update(completion: @escaping (CallResult)->())
    throws -> Echo_EchoUpdateCall

}

internal final class Echo_EchoServiceImpl: Echo_EchoService {
  internal private(set) var channel: Channel

  internal var metadata : Metadata

  internal var host : String {
    get {
      return self.channel.host
