Skip to content

Commit

Permalink
refactor!: remove accountPool from ClientPool
Browse files Browse the repository at this point in the history
  • Loading branch information
kory33 committed Nov 28, 2021
1 parent d90ed60 commit 5dc56f4
Showing 1 changed file with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ import io.github.kory33.s2mctest.core.client.SightedClient

trait ClientPool[F[_], ServerBoundPackets <: Tuple, ClientBoundPackets <: Tuple, WorldView] {

final type AssociatedServerBoundPackets = ServerBoundPackets
final type AssociatedClientBoundPackets = ClientBoundPackets
final type Client = SightedClient[F, ServerBoundPackets, ClientBoundPackets, WorldView]

/**
* The account pool from which client usernames are atomically generated.
*/
val accountPool: AccountPool[F]

/**
* [[Resource]] of a client that is guaranteed to be in a state right after login has
* completed.
Expand Down Expand Up @@ -45,24 +38,20 @@ object ClientPool {
ClientBoundPackets <: Tuple,
State
](
_accountPool: AccountPool[F],
accountPool: AccountPool[F],
initialState: State,
init: ClientInitialization[F, ServerBoundPackets, ClientBoundPackets, State]
) {

final type PoolWith[AccountPool] =
ClientPool[F, ServerBoundPackets, ClientBoundPackets, State] {
val accountPool: AccountPool
}

import cats.implicits.given

/**
* Create a cached account pool. Cached account pools do not have a maximum bound of active
* connections, but will stop caching the connections once the total number of clients
* reaches [[softBound]].
*/
def cached(softBound: Int): F[PoolWith[_accountPool.type]] = {
def cached(softBound: Int)
: F[ClientPool[F, ServerBoundPackets, ClientBoundPackets, State]] = {

/**
* A dormant client cached inside the pool.
Expand Down Expand Up @@ -116,8 +105,6 @@ object ClientPool {
_ <- if cached then Monad[F].unit else cancelPacketReadLoop >> clientFinalizer
} yield ()

override val accountPool: _accountPool.type = _accountPool

override val freshClient: Resource[F, Client] = {
val allocate: F[(Client, F[Unit])] =
accountPool.getFresh >>= (init.initializeFresh(_, initialState).allocated[Client])
Expand Down

0 comments on commit 5dc56f4

Please sign in to comment.