Skip to content

Commit

Permalink
Cross compile to scala3 (#10)
Browse files Browse the repository at this point in the history
This MR adds cross-compilation to scala 3.3.3. 
I also removed kind-projector because a single usage doesn't justify it
enough (basically more code to add it than the number of lines it saves)

---------

Co-authored-by: avoitsishevskii <[email protected]>
  • Loading branch information
FunFunFine and evo-funfunfine authored Sep 4, 2024
1 parent 92c41bc commit 2edd670
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
matrix:
scala:
- 2.13.14
- 3.3.3

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 5 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ organizationHomepage := Some(url("https://evolution.com"))
homepage := Some(url("https://github.com/evolution-gaming/resource-pool"))
startYear := Some(2023)

crossScalaVersions := Seq("2.13.14")
crossScalaVersions := Seq("2.13.14", "3.3.3")
scalaVersion := crossScalaVersions.value.head
releaseCrossBuild := true
scalacOptions := Seq(
"-release:17",
"-Xsource:3",
"-deprecation",
"-deprecation"
)
autoAPIMappings := true
versionScheme := Some("early-semver")
publishTo := Some(Resolver.evolutionReleases) // sbt-release
versionPolicyIntention := Compatibility.BinaryCompatible // sbt-version-policy

libraryDependencies += compilerPlugin(`kind-projector` cross CrossVersion.full)

libraryDependencies ++= Seq(
`cats-effect`,
scalatest,
scalatest
)

licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT")))
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/com/evolution/resourcepool/ResourcePool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ResourcePool {
discardTasksOnRelease: Boolean,
resource: Id => Resource[F, A]
): Resource[F, ResourcePool[F, A]] = {

type ResourceF[+AA] = Resource[F, AA]
def apply(maxSize: Int, partitions: Int) = {

def of(maxSize: Int)(resource: Id => Resource[F, A]) = {
Expand All @@ -99,13 +99,13 @@ object ResourcePool {
} else {
for {
ref <- Ref[F].of(0).toResource
values <- maxSize
values1 <- maxSize
.divide(partitions)
.zipWithIndex
.parTraverse { case (maxSize, idx) => of(maxSize) { id => resource(s"$idx-$id") } }
values <- values
values <- values1
.toVector
.pure[Resource[F, *]]
.pure[ResourceF]
length = values.length
} yield {
new ResourcePool[F, A] {
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/com/evolution/resourcepool/ResourcePoolTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import scala.concurrent.duration.*
import scala.util.control.NoStackTrace

class ResourcePoolTest extends AsyncFunSuite with Matchers {

type IOResource[+A] = Resource[IO, A]
test("handle invalid `maxSize`") {
()
.pure[Resource[IO, *]]
.pure[IOResource]
.toResourcePool(
maxSize = 1,
expireAfter = 1.day,
Expand Down Expand Up @@ -114,7 +114,7 @@ class ResourcePoolTest extends AsyncFunSuite with Matchers {
test("fail after being released") {
val result = for {
result <- ()
.pure[Resource[IO, *]]
.pure[IOResource]
.toResourcePool(
maxSize = 2,
expireAfter = 1.day)
Expand Down Expand Up @@ -433,7 +433,7 @@ class ResourcePoolTest extends AsyncFunSuite with Matchers {
val result = for {
deferred0 <- Deferred[IO, Unit].toResource
pool <- ()
.pure[Resource[IO, *]]
.pure[IOResource]
.toResourcePool(
maxSize = 1,
expireAfter = 1.day)
Expand Down Expand Up @@ -469,7 +469,7 @@ class ResourcePoolTest extends AsyncFunSuite with Matchers {
val result = for {
deferred0 <- Deferred[IO, Unit].toResource
pool <- ()
.pure[Resource[IO, *]]
.pure[IOResource]
.toResourcePool(
maxSize = 1,
expireAfter = 1.day)
Expand Down Expand Up @@ -633,7 +633,7 @@ class ResourcePoolTest extends AsyncFunSuite with Matchers {
test("discard tasks on release") {
val result = for {
result <- ()
.pure[Resource[IO, *]]
.pure[IOResource]
.toResourcePool(
maxSize = 1,
expireAfter = 1.day,
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "1.0.5-SNAPSHOT"
ThisBuild / version := "2.0.0"

0 comments on commit 2edd670

Please sign in to comment.