---
title: "sendSync(_:)"
framework: xpc
role: symbol
role_heading: Instance Method
path: "xpc/xpcsession/sendsync(_:)-88u0s"
---

# sendSync(_:)

Sends an encodable message over the session to the destination service, blocking the caller until receiving an encodable reply message.

## Declaration

```swift
func sendSync<Message, Reply>(_ message: Message) throws -> Reply where Message : Encodable, Reply : Decodable
```

## Parameters

- `message`: An encodable object that contains the message to send.

## Return Value

Return Value If successful, the response to the message; otherwise this method throws an error.

## Discussion

Discussion This method supports priority inversion avoidance. Use this method instead of calling send(message:replyHandler:) and using a semaphore. Be judicious about your use of this API. It can block indefinitely. Calling this method while the session’s target queue is blocked may lead to deadlocks in certain scenarios. For that reason, invoking this method from the session’s target queue results in a crash. tip: If you provide an API that uses this method, consider allowing callers to specify a queue and callback handler to let you provide results asynchronously. Sessions send messages serially in a first-in, first-out (FIFO) order. This method is safe to call from multiple dispatch queues. The session can’t indicate whether the message delivery is successful or not. While the session may successfully enqueue the message at the remote end of the connection, there’s no guarantee about when the destination dequeues the message and invokes the receiving session’s handler. important: If you create an inactive session, you must activate it before sending messages. Calling this method with an inactive session crashes.

## See Also

### Sending messages

- [send(_:)](xpc/xpcsession/send(_:).md)
- [send(_:replyHandler:)](xpc/xpcsession/send(_:replyhandler:)-3wjln.md)
- [send(_:replyHandler:)](xpc/xpcsession/send(_:replyhandler:)-9an0u.md)
- [send(message:)](xpc/xpcsession/send(message:).md)
- [send(message:replyHandler:)](xpc/xpcsession/send(message:replyhandler:).md)
- [sendSync(_:)](xpc/xpcsession/sendsync(_:)-8a284.md)
- [sendSync(message:)](xpc/xpcsession/sendsync(message:).md)
