-
Notifications
You must be signed in to change notification settings - Fork 17
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
DRAFT: Scala3 cross-compilation; #657
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -5,9 +5,11 @@ import com.evolutiongaming.catshelper.ApplicativeThrowable | |
import pureconfig.ConfigReader | ||
import pureconfig.error.ConfigReaderException | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait FromConfigReaderResult[F[_]] { | ||
|
||
def apply[A](a: ConfigReader.Result[A]): F[A] | ||
def apply[A: ClassTag](a: ConfigReader.Result[A]): F[A] | ||
} | ||
|
||
object FromConfigReaderResult { | ||
|
@@ -16,7 +18,7 @@ object FromConfigReaderResult { | |
|
||
implicit def lift[F[_]: ApplicativeThrowable]: FromConfigReaderResult[F] = { | ||
new FromConfigReaderResult[F] { | ||
def apply[A](a: ConfigReader.Result[A]) = { | ||
def apply[A: ClassTag](a: ConfigReader.Result[A]): F[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. why we need 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. the version of pureconfig that was published for Scala 3, some of its APIs were updated and now require ClassTag |
||
a.fold(a => ConfigReaderException(a).raiseError[F, A], _.pure[F]) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,68 @@ object HostName { | |
def of[F[_]: Sync](): F[Option[HostName]] = { | ||
Sync[F].delay { | ||
for { | ||
a <- com.evolutiongaming.hostname.HostName() | ||
a <- EvoHostName() | ||
} yield { | ||
HostName(a) | ||
} | ||
} | ||
} | ||
} | ||
|
||
import java.net.InetAddress | ||
import java.util.concurrent.Executors | ||
|
||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Await, ExecutionContext, Future} | ||
import scala.sys.process.* | ||
import scala.util.Properties | ||
import scala.util.control.NonFatal | ||
|
||
/** Copied from https://github.com/evolution-gaming/hostname */ | ||
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. is this temporary copy till 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. Both yes and no. If you feel like it should stay as a dependency, I'll update the library. But if you agree on it making no sense, then I'll refactor this file and make it nice. |
||
object EvoHostName { | ||
|
||
def apply(): Option[String] = { | ||
|
||
val os = env("os.name").map(_.toLowerCase) | ||
|
||
{ | ||
if (os contains "win") win() | ||
else if ((os contains "nix") || (os contains "nux") || (os contains "mac")) unix() | ||
else unix() orElse win() | ||
} orElse { | ||
inetAddress() | ||
} | ||
} | ||
|
||
private def inetAddress() = { | ||
val service = Executors.newSingleThreadExecutor() | ||
implicit val ec = ExecutionContext.fromExecutor(service) | ||
val future = Future { | ||
InetAddress.getLocalHost.getHostName | ||
} | ||
future.onComplete { _ => service.shutdown() } | ||
safe { Await.result(future, 1.second) }.filter(str => str != "localhost") | ||
} | ||
|
||
private def win() = | ||
env("COMPUTERNAME") orElse | ||
exec("hostname") | ||
|
||
private def unix() = | ||
env("HOSTNAME") orElse | ||
exec("hostname") orElse | ||
env("gethostname") orElse | ||
exec("cat /etc/hostname") | ||
|
||
private def exec(name: String) = safe { name.!! } | ||
|
||
private def env(name: String) = Properties.envOrNone(name) | ||
|
||
private def safe(f: => String) = { | ||
try { | ||
Option(f.trim).filter(_.nonEmpty) | ||
} catch { | ||
case NonFatal(_) => None | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,11 @@ object GracefulFiber { | |
def join = fiber.join | ||
|
||
def cancel = { | ||
for { | ||
cancel <- cancelRef.getAndSet(true) | ||
_ <- if (cancel) ().pure[F] else fiber.joinWithNever | ||
} yield {} | ||
cancelRef.getAndSet(true) | ||
.flatMap(cancel => | ||
(if (cancel) ().pure[F] else fiber.joinWithNever.void) | ||
|
||
) | ||
Comment on lines
+26
to
+30
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. why replace for comprehension with I can see usage of 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. It's forced by a weird scala 3 typing-in-for-compresensions issue. Basically the old version can't infer types in the last syntetic map ( 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. so I just did 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. Perhaps it might compile with .void that I also put there, I'll check |
||
} | ||
} | ||
} | ||
|
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.
please update matrix in
ci.yml
file too