1

I am using https://github.com/grpc/grpc-swift for inter-process communication. I have a GRPC server written in Go that listens on a unix domain socket, and a macOS app written in Swift that communicates with it over the socket.

Let's say the Go server process is not running and I make an RPC call from my Swift program. The default timeout before the call will fail is 20 seconds, but I would like to shorten it to 1 second. I am trying to do something like this:

let callOptions = CallOptions(timeLimit: .seconds(1)) // <-- Does not compile

This fails with compile error Type 'TimeLimit' has no member 'seconds'.

What is the correct way to decrease the timeout interval for Swift GRPC calls?

Clément Jean
  • 1,735
  • 1
  • 14
  • 32
fsctl
  • 161
  • 8

1 Answers1

1

As mentioned in the error TimeLimit don't have a member seconds. This seconds function that you are trying to access is inside TimeAmount. So if you want to use a deadline, you will need to use:

CallOptions(timeLimit: .deadline(.now() + .seconds(1)))

here the .now is inside NIODeadline and it as a + operator defined for adding with TimeLimit (check here).

and for a timeout:

CallOptions(timeLimit: .timeout(.seconds(1)))

Note that I'm not an expert in Swift, but I checked in TimeLimitTests.swift and that seems to be the idea.

Clément Jean
  • 1,735
  • 1
  • 14
  • 32
  • This leads to a compile error also: "Type 'NIODeadline' has no member 'seconds'" – fsctl Jun 03 '22 at 18:12
  • 1
    But the tests link in your post helped me find a solution! `CallOptions(timeLimit: TimeLimit.timeout(.seconds(1)))` compiles and has the desired behavior. If you update your answer to this, I will mark it as the correct answer. – fsctl Jun 03 '22 at 18:24
  • Note: Timeout and Deadline are different concepts, I recommend you to check the one that is best for your use case – Clément Jean Jun 04 '22 at 04:41