-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOApp.ResourceApp #1958
IOApp.ResourceApp #1958
Changes from 8 commits
4b59f1e
43f9c63
dec0454
8f06dc1
9519e10
b59f3ae
82dd2ca
7aae28d
0a6619a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,7 @@ trait IOApp { | |
Thread.currentThread().interrupt() | ||
} | ||
} | ||
|
||
} | ||
|
||
object IOApp { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, if even just for consistency with the other ones. I would certainly use it, since we usually take arguments from env vars. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really think it makes sense to have an
ExitCode
here... does it? also, you'll notice it doesn't extendResourceApp
for that reason, but also because we can't overridemain
since it's declaredfinal
for nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm good with Unit / Any