Skip to content

Commit

Permalink
feat(client): resolve #31
Browse files Browse the repository at this point in the history
  • Loading branch information
kory33 committed Nov 28, 2021
1 parent 5dc56f4 commit 341768c
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.kory33.s2mctest.core.clientpool
import cats.effect.MonadCancelThrow
import cats.effect.kernel.{Ref, Resource}
import cats.{Monad, MonadThrow}
import io.github.kory33.s2mctest.core.client.SightedClient
import io.github.kory33.s2mctest.core.client.{ClientIdentity, SightedClient}

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

Expand All @@ -28,6 +28,21 @@ trait ClientPool[F[_], ServerBoundPackets <: Tuple, ClientBoundPackets <: Tuple,
*/
val recycledClient: Resource[F, Client]

type Identity

/**
* A [[Resource]] that acquires a new [[Identity]] that can be used to create a [[Client]] via
* [[uncachedClientWith]] method.
*/
val freshIdentity: Resource[F, Identity]

/**
* Create a client that is guaranteed to have [[Identity]] as an identity. The acquired client
* is never cached; it is guaranteed that the client has been disconnected by the time the
* returned resource went out of scope.
*/
def uncachedClientWith(account: Identity): Resource[F, Client]

}

object ClientPool {
Expand Down Expand Up @@ -134,6 +149,13 @@ object ClientPool {
case None => freshClient
}
}

override type Identity = String

override val freshIdentity: Resource[F, Identity] = Resource.eval(accountPool.getFresh)

override def uncachedClientWith(account: Identity): Resource[F, Client] =
init.initializeFresh(account, initialState)
}
}
}
Expand Down

0 comments on commit 341768c

Please sign in to comment.