From 4b59f1e2ee37d1496dbea608dd4ad1f059bebdb2 Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Mon, 10 May 2021 21:47:53 -0500 Subject: [PATCH 1/9] Add IOApp.ResourceApp and IOApp.SimpleResource --- core/js/src/main/scala/cats/effect/IOApp.scala | 10 ++++++++++ core/jvm/src/main/scala/cats/effect/IOApp.scala | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/js/src/main/scala/cats/effect/IOApp.scala b/core/js/src/main/scala/cats/effect/IOApp.scala index 62e1b2a2f2..bd9819d381 100644 --- a/core/js/src/main/scala/cats/effect/IOApp.scala +++ b/core/js/src/main/scala/cats/effect/IOApp.scala @@ -97,4 +97,14 @@ object IOApp { final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) } + trait ResourceApp extends IOApp { + def runResource(args: List[String]): Resource[IO, ExitCode] + final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) + } + + trait SimpleResource extends ResourceApp { + def runResource: Resource[IO, Unit] + final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) + } + } diff --git a/core/jvm/src/main/scala/cats/effect/IOApp.scala b/core/jvm/src/main/scala/cats/effect/IOApp.scala index 60a02c95de..420828e6cb 100644 --- a/core/jvm/src/main/scala/cats/effect/IOApp.scala +++ b/core/jvm/src/main/scala/cats/effect/IOApp.scala @@ -16,6 +16,9 @@ package cats.effect +import cats.effect.kernel.Resource +import cats.syntax.all._ + import scala.concurrent.{blocking, CancellationException} import java.util.concurrent.CountDownLatch @@ -148,4 +151,14 @@ object IOApp { final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) } + trait ResourceApp extends IOApp { + def runResource(args: List[String]): Resource[IO, ExitCode] + final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) + } + + trait SimpleResource extends ResourceApp { + def runResource: Resource[IO, Unit] + final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) + } + } From 43f9c63f837af6d6eaeae393a6921052a520840a Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Mon, 10 May 2021 21:48:22 -0500 Subject: [PATCH 2/9] Rename SimpleResource to SimpleResourceApp --- core/js/src/main/scala/cats/effect/IOApp.scala | 2 +- core/jvm/src/main/scala/cats/effect/IOApp.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/src/main/scala/cats/effect/IOApp.scala b/core/js/src/main/scala/cats/effect/IOApp.scala index bd9819d381..809ef5137d 100644 --- a/core/js/src/main/scala/cats/effect/IOApp.scala +++ b/core/js/src/main/scala/cats/effect/IOApp.scala @@ -102,7 +102,7 @@ object IOApp { final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) } - trait SimpleResource extends ResourceApp { + trait SimpleResourceApp extends ResourceApp { def runResource: Resource[IO, Unit] final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) } diff --git a/core/jvm/src/main/scala/cats/effect/IOApp.scala b/core/jvm/src/main/scala/cats/effect/IOApp.scala index 420828e6cb..410a4dcf97 100644 --- a/core/jvm/src/main/scala/cats/effect/IOApp.scala +++ b/core/jvm/src/main/scala/cats/effect/IOApp.scala @@ -156,7 +156,7 @@ object IOApp { final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) } - trait SimpleResource extends ResourceApp { + trait SimpleResourceApp extends ResourceApp { def runResource: Resource[IO, Unit] final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) } From dec0454941e05a90097e733bfb6445d0c793c297 Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Mon, 10 May 2021 21:52:55 -0500 Subject: [PATCH 3/9] Share IOApp with IOAppPlatform traits --- .../{IOApp.scala => IOAppPlatform.scala} | 23 +--------- .../{IOApp.scala => IOAppPlatform.scala} | 25 +---------- .../src/main/scala/cats/effect/IOApp.scala | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 46 deletions(-) rename core/js/src/main/scala/cats/effect/{IOApp.scala => IOAppPlatform.scala} (83%) rename core/jvm/src/main/scala/cats/effect/{IOApp.scala => IOAppPlatform.scala} (85%) create mode 100644 core/shared/src/main/scala/cats/effect/IOApp.scala diff --git a/core/js/src/main/scala/cats/effect/IOApp.scala b/core/js/src/main/scala/cats/effect/IOAppPlatform.scala similarity index 83% rename from core/js/src/main/scala/cats/effect/IOApp.scala rename to core/js/src/main/scala/cats/effect/IOAppPlatform.scala index 809ef5137d..707cc1c7ae 100644 --- a/core/js/src/main/scala/cats/effect/IOApp.scala +++ b/core/js/src/main/scala/cats/effect/IOAppPlatform.scala @@ -20,15 +20,13 @@ import scala.concurrent.CancellationException import scala.concurrent.duration._ import scala.scalajs.js -trait IOApp { +trait IOAppPlatform { this: IOApp => private[this] var _runtime: unsafe.IORuntime = null protected def runtime: unsafe.IORuntime = _runtime protected def runtimeConfig: unsafe.IORuntimeConfig = unsafe.IORuntimeConfig() - def run(args: List[String]): IO[ExitCode] - final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime @@ -89,22 +87,3 @@ trait IOApp { js.Dynamic.global.process.exitCode = code.code } } - -object IOApp { - - trait Simple extends IOApp { - def run: IO[Unit] - final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) - } - - trait ResourceApp extends IOApp { - def runResource(args: List[String]): Resource[IO, ExitCode] - final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) - } - - trait SimpleResourceApp extends ResourceApp { - def runResource: Resource[IO, Unit] - final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) - } - -} diff --git a/core/jvm/src/main/scala/cats/effect/IOApp.scala b/core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala similarity index 85% rename from core/jvm/src/main/scala/cats/effect/IOApp.scala rename to core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala index 410a4dcf97..606276be0a 100644 --- a/core/jvm/src/main/scala/cats/effect/IOApp.scala +++ b/core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala @@ -16,14 +16,11 @@ package cats.effect -import cats.effect.kernel.Resource -import cats.syntax.all._ - import scala.concurrent.{blocking, CancellationException} import java.util.concurrent.CountDownLatch -trait IOApp { +trait IOAppPlatform { this: IOApp => private[this] var _runtime: unsafe.IORuntime = null protected def runtime: unsafe.IORuntime = _runtime @@ -33,8 +30,6 @@ trait IOApp { protected def computeWorkerThreadCount: Int = Math.max(2, Runtime.getRuntime().availableProcessors()) - def run(args: List[String]): IO[ExitCode] - final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime @@ -142,23 +137,5 @@ trait IOApp { Thread.currentThread().interrupt() } } -} - -object IOApp { - - trait Simple extends IOApp { - def run: IO[Unit] - final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) - } - - trait ResourceApp extends IOApp { - def runResource(args: List[String]): Resource[IO, ExitCode] - final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) - } - - trait SimpleResourceApp extends ResourceApp { - def runResource: Resource[IO, Unit] - final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) - } } diff --git a/core/shared/src/main/scala/cats/effect/IOApp.scala b/core/shared/src/main/scala/cats/effect/IOApp.scala new file mode 100644 index 0000000000..3565a223f5 --- /dev/null +++ b/core/shared/src/main/scala/cats/effect/IOApp.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2020-2021 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect + +import cats.effect.kernel.Resource +import cats.syntax.all._ + +trait IOApp extends IOAppPlatform { + def run(args: List[String]): IO[ExitCode] +} + +object IOApp { + + trait Simple extends IOApp { + def run: IO[Unit] + final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) + } + + trait ResourceApp extends IOApp { + def runResource(args: List[String]): Resource[IO, ExitCode] + final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) + } + + trait SimpleResourceApp extends ResourceApp { + def runResource: Resource[IO, Unit] + final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) + } + +} From 8f06dc12658aff410a1cc084b2948efcad639410 Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Mon, 10 May 2021 21:55:17 -0500 Subject: [PATCH 4/9] scalafmt --- core/shared/src/main/scala/cats/effect/IOApp.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/cats/effect/IOApp.scala b/core/shared/src/main/scala/cats/effect/IOApp.scala index 3565a223f5..b94d0f809d 100644 --- a/core/shared/src/main/scala/cats/effect/IOApp.scala +++ b/core/shared/src/main/scala/cats/effect/IOApp.scala @@ -37,7 +37,8 @@ object IOApp { trait SimpleResourceApp extends ResourceApp { def runResource: Resource[IO, Unit] - final def runResource(args: List[String]): Resource[IO, ExitCode] = runResource.as(ExitCode.Success) + final def runResource(args: List[String]): Resource[IO, ExitCode] = + runResource.as(ExitCode.Success) } } From 9519e109d1e60875c3e4c121b2e1d5308e18cc27 Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Mon, 10 May 2021 22:24:11 -0500 Subject: [PATCH 5/9] Remove hidden reference --- core/shared/src/main/scala/cats/effect/IOApp.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/core/shared/src/main/scala/cats/effect/IOApp.scala b/core/shared/src/main/scala/cats/effect/IOApp.scala index b94d0f809d..8643ae627e 100644 --- a/core/shared/src/main/scala/cats/effect/IOApp.scala +++ b/core/shared/src/main/scala/cats/effect/IOApp.scala @@ -16,7 +16,6 @@ package cats.effect -import cats.effect.kernel.Resource import cats.syntax.all._ trait IOApp extends IOAppPlatform { From b59f3aec641966a4a282d7c5c7be7aa662d763dd Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Wed, 26 May 2021 23:56:26 -0500 Subject: [PATCH 6/9] Revert platform trait sharing --- .../effect/{IOAppPlatform.scala => IOApp.scala} | 13 ++++++++++++- .../effect/{IOAppPlatform.scala => IOApp.scala} | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) rename core/js/src/main/scala/cats/effect/{IOAppPlatform.scala => IOApp.scala} (93%) rename core/jvm/src/main/scala/cats/effect/{IOAppPlatform.scala => IOApp.scala} (94%) diff --git a/core/js/src/main/scala/cats/effect/IOAppPlatform.scala b/core/js/src/main/scala/cats/effect/IOApp.scala similarity index 93% rename from core/js/src/main/scala/cats/effect/IOAppPlatform.scala rename to core/js/src/main/scala/cats/effect/IOApp.scala index 707cc1c7ae..c3077164b8 100644 --- a/core/js/src/main/scala/cats/effect/IOAppPlatform.scala +++ b/core/js/src/main/scala/cats/effect/IOApp.scala @@ -20,13 +20,15 @@ import scala.concurrent.CancellationException import scala.concurrent.duration._ import scala.scalajs.js -trait IOAppPlatform { this: IOApp => +trait IOApp { private[this] var _runtime: unsafe.IORuntime = null protected def runtime: unsafe.IORuntime = _runtime protected def runtimeConfig: unsafe.IORuntimeConfig = unsafe.IORuntimeConfig() + def run(args: List[String]): IO[ExitCode] + final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime @@ -87,3 +89,12 @@ trait IOAppPlatform { this: IOApp => js.Dynamic.global.process.exitCode = code.code } } + +object IOApp { + + trait Simple extends IOApp { + def run: IO[Unit] + final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) + } + +} diff --git a/core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala b/core/jvm/src/main/scala/cats/effect/IOApp.scala similarity index 94% rename from core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala rename to core/jvm/src/main/scala/cats/effect/IOApp.scala index 606276be0a..c282930d7c 100644 --- a/core/jvm/src/main/scala/cats/effect/IOAppPlatform.scala +++ b/core/jvm/src/main/scala/cats/effect/IOApp.scala @@ -20,7 +20,7 @@ import scala.concurrent.{blocking, CancellationException} import java.util.concurrent.CountDownLatch -trait IOAppPlatform { this: IOApp => +trait IOApp { private[this] var _runtime: unsafe.IORuntime = null protected def runtime: unsafe.IORuntime = _runtime @@ -30,6 +30,8 @@ trait IOAppPlatform { this: IOApp => protected def computeWorkerThreadCount: Int = Math.max(2, Runtime.getRuntime().availableProcessors()) + def run(args: List[String]): IO[ExitCode] + final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime @@ -139,3 +141,12 @@ trait IOAppPlatform { this: IOApp => } } + +object IOApp { + + trait Simple extends IOApp { + def run: IO[Unit] + final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) + } + +} From 82dd2cac9731f84db68a2180313305546e545d2a Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Thu, 27 May 2021 00:09:50 -0500 Subject: [PATCH 7/9] ResourceApp --- .../src/main/scala/cats/effect/IOApp.scala | 43 --------------- .../main/scala/cats/effect/ResourceApp.scala | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+), 43 deletions(-) delete mode 100644 core/shared/src/main/scala/cats/effect/IOApp.scala create mode 100644 core/shared/src/main/scala/cats/effect/ResourceApp.scala diff --git a/core/shared/src/main/scala/cats/effect/IOApp.scala b/core/shared/src/main/scala/cats/effect/IOApp.scala deleted file mode 100644 index 8643ae627e..0000000000 --- a/core/shared/src/main/scala/cats/effect/IOApp.scala +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020-2021 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cats.effect - -import cats.syntax.all._ - -trait IOApp extends IOAppPlatform { - def run(args: List[String]): IO[ExitCode] -} - -object IOApp { - - trait Simple extends IOApp { - def run: IO[Unit] - final def run(args: List[String]): IO[ExitCode] = run.as(ExitCode.Success) - } - - trait ResourceApp extends IOApp { - def runResource(args: List[String]): Resource[IO, ExitCode] - final def run(args: List[String]): IO[ExitCode] = runResource(args).use(IO.pure(_)) - } - - trait SimpleResourceApp extends ResourceApp { - def runResource: Resource[IO, Unit] - final def runResource(args: List[String]): Resource[IO, ExitCode] = - runResource.as(ExitCode.Success) - } - -} diff --git a/core/shared/src/main/scala/cats/effect/ResourceApp.scala b/core/shared/src/main/scala/cats/effect/ResourceApp.scala new file mode 100644 index 0000000000..c3892b1986 --- /dev/null +++ b/core/shared/src/main/scala/cats/effect/ResourceApp.scala @@ -0,0 +1,52 @@ +/* + * Copyright 2020-2021 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect + +import cats.syntax.all._ + +trait ResourceApp { self => + def run(args: List[String]): Resource[IO, ExitCode] + + final def main(args: Array[String]): Unit = { + val ioApp = new IOApp { + override def run(args: List[String]): IO[ExitCode] = + self.run(args).use(IO.pure(_)) + } + + ioApp.main(args) + } +} + +object ResourceApp { + trait Simple extends ResourceApp { + def run: Resource[IO, Unit] + final def run(args: List[String]): Resource[IO, ExitCode] = run.as(ExitCode.Success) + } + + trait Forever { self => + def run(args: List[String]): Resource[IO, Unit] + + final def main(args: Array[String]): Unit = { + val ioApp = new IOApp { + override def run(args: List[String]): IO[ExitCode] = + self.run(args).useForever + } + + ioApp.main(args) + } + } +} From 7aae28d1795b1c77629548b62b5f88de852e695c Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Thu, 27 May 2021 00:10:05 -0500 Subject: [PATCH 8/9] Scalafmt --- core/jvm/src/main/scala/cats/effect/IOApp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/jvm/src/main/scala/cats/effect/IOApp.scala b/core/jvm/src/main/scala/cats/effect/IOApp.scala index c282930d7c..5f6ca0976a 100644 --- a/core/jvm/src/main/scala/cats/effect/IOApp.scala +++ b/core/jvm/src/main/scala/cats/effect/IOApp.scala @@ -31,7 +31,7 @@ trait IOApp { Math.max(2, Runtime.getRuntime().availableProcessors()) def run(args: List[String]): IO[ExitCode] - + final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime From 0a6619a1efde7baf2f3cff47b87c94cb02435fb7 Mon Sep 17 00:00:00 2001 From: Raas Ahsan Date: Thu, 27 May 2021 00:13:21 -0500 Subject: [PATCH 9/9] Scalafmt again --- core/js/src/main/scala/cats/effect/IOApp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/js/src/main/scala/cats/effect/IOApp.scala b/core/js/src/main/scala/cats/effect/IOApp.scala index c3077164b8..62e1b2a2f2 100644 --- a/core/js/src/main/scala/cats/effect/IOApp.scala +++ b/core/js/src/main/scala/cats/effect/IOApp.scala @@ -28,7 +28,7 @@ trait IOApp { protected def runtimeConfig: unsafe.IORuntimeConfig = unsafe.IORuntimeConfig() def run(args: List[String]): IO[ExitCode] - + final def main(args: Array[String]): Unit = { if (runtime == null) { import unsafe.IORuntime