Instance Method
run()
The structured root task for the client’s background work.
func run() async
Discussion
Warning
Users must call this function in order to allow the client to process any background work. Executing queries, prepared statements or leasing connections will hang until the developer executes the client’s run() method.
Cancelling the task that executes the run() method is equivalent to closing the client. Once the task has been cancelled the client is not able to process any new queries or prepared statements.
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
await client.run() // !important
}
// You can use the client while the `client.run()` method is not cancelled.
// To shutdown the client, cancel its run method, by cancelling the taskGroup.
taskGroup.cancelAll()
}
Note
PostgresClient implements ServiceLifecycle’s Service protocol. Because of this PostgresClient can be passed to a ServiceGroup for easier lifecycle management.