ConnectionPool

public final class ConnectionPool

Connection pool management.

  • Disclose init

    Declaration

    Swift

    public init()
  • Allocates a connection object and returns it.

    Note

    This is a synchronous operation.

    Declaration

    Swift

    public func allocate() -> Connection?

    Return Value

    A connection object if available, otherwise nil.

  • Allocates a connection object if it becomes available within the timeout period.

    Declaration

    Swift

    public func allocateOrTimeout(_ timeout: Int) -> (Int, Connection?)

    Parameters

    timeout

    An integer specifying the timout in seconds.

    Return Value

    The number of seconds until the connection was availeble and the connection object itself or nil after the timeout expires.

  • Moves the given connection object from the ‘used’ to the ‘available’ pool.

    Note

    This is a synchronous operation.

    Declaration

    Swift

    public func free(connection: Connection) -> Result<Bool>

    Parameters

    connection

    The connection object to move from the used to the available pool.

    Return Value

    Either .success(true) or .error(message: String).

  • Removes all old connection objects and creates new ones. This function will remove all free connection objects from the pool. Then it will wait until the connections that are in use will become free before removing them. Keep in mind that when there is a reasonable load, this can result in degraded performance for a long time as connections that become free will immediately be picked up again before they can be removed. It would be better to stop the server while this function is called and start again it afterwards.

    Note

    This is a synchronous operation.

    Declaration

    Swift

    public func create(num: Int, generator: @escaping () -> Connection)

    Parameters

    num

    The number of new connections objects to create.

    generator

    A closure that creates new connection objects.