HotswapRef

trait HotswapRef[F[_], R]

A concurrent data structure that wraps a cats.effect.std.Hotswap providing access to R using a cats.effect.kernel.Ref, that is set on resource acquisition, while providing asynchronous hotswap functionality via calls to swap.

A concurrent data structure that wraps a cats.effect.std.Hotswap providing access to R using a cats.effect.kernel.Ref, that is set on resource acquisition, while providing asynchronous hotswap functionality via calls to swap.

In short, calls to swap do not block the usage of R via calls to access.

Repeated concurrent calls to swap are ordered by a semaphore to ensure that R doesn't churn unexpectedly. As with calls to swap on cats.effect.std.Hotswap, swap will block until the previous cats.effect.kernel.Resource is finalized. Additionally open references to R are counted when it is accessed via access, any R with open references will block at finalization until all references are released, and therefore subsequent calls to swap will block.

Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def access: Resource[F, R]

Access R safely

Access R safely

Note that access to R is protected by a shared-mode lock via a cats.effect.kernel.Resource scope. A resource R with unreleased locks cannot be finalized and therefore cannot be fully swapped.

def swap(next: Resource[F, R]): F[Unit]

Swap the current resource with a new version

Swap the current resource with a new version

This makes use of evalTap on the provided cats.effect.kernel.Resource to ensure the cats.effect.kernel.Ref with R is updated immediately on allocation and may be used by access calls while swap blocks, waiting for the previous cats.effect.kernel.Resource to finalize.

This means that while there is no previous finalization process in progress when this is called, R may be swapped in the holder ref, but will block until all references to R are removed and R is torn down.

A semaphore guarantees that concurrent access to swap will wait while previous resources are finalized.