diff --git a/cache/js/src/main/scala/coursier/Platform.scala b/cache/js/src/main/scala/coursier/Platform.scala index 2b3d0dbe2..8d43d7ce9 100644 --- a/cache/js/src/main/scala/coursier/Platform.scala +++ b/cache/js/src/main/scala/coursier/Platform.scala @@ -1,6 +1,6 @@ package coursier -import coursier.util.EitherT +import coursier.util.{EitherT, Task} import org.scalajs.dom.raw.{Event, XMLHttpRequest} import scala.concurrent.{ExecutionContext, Future, Promise} diff --git a/cache/js/src/main/scala/coursier/Task.scala b/cache/js/src/main/scala/coursier/Task.scala deleted file mode 100644 index 70d6aedf5..000000000 --- a/cache/js/src/main/scala/coursier/Task.scala +++ /dev/null @@ -1,49 +0,0 @@ -package coursier - -import coursier.util.Gather - -import scala.concurrent.{ExecutionContext, Future} - -/** - * Minimal Future-based Task. - * - * Likely to be flawed and/or sub-optimal, but does the job. - */ -trait Task[T] { self => - def map[U](f: T => U): Task[U] = - new Task[U] { - def runF(implicit ec: ExecutionContext) = self.runF.map(f) - } - def flatMap[U](f: T => Task[U]): Task[U] = - new Task[U] { - def runF(implicit ec: ExecutionContext) = self.runF.flatMap(f(_).runF) - } - - def runF(implicit ec: ExecutionContext): Future[T] -} - -object Task { - def now[A](a: A): Task[A] = - new Task[A] { - def runF(implicit ec: ExecutionContext) = Future.successful(a) - } - def apply[A](f: ExecutionContext => Future[A]): Task[A] = - new Task[A] { - def runF(implicit ec: ExecutionContext) = f(ec) - } - def gatherUnordered[T](tasks: Seq[Task[T]], exceptionCancels: Boolean = false): Task[Seq[T]] = - new Task[Seq[T]] { - def runF(implicit ec: ExecutionContext) = Future.traverse(tasks)(_.runF) - } - - implicit val gather: Gather[Task] = - new Gather[Task] { - def point[A](a: A): Task[A] = Task.now(a) - def bind[A,B](fa: Task[A])(f: A => Task[B]): Task[B] = fa.flatMap(f) - def gather[A](elems: Seq[Task[A]]): Task[Seq[A]] = { - Task { implicit ec => - Future.sequence(elems.map(_.runF)) - } - } - } -} diff --git a/tests/js/src/test/scala/coursier/test/JsTests.scala b/tests/js/src/test/scala/coursier/test/JsTests.scala index 55bc44213..c566e5519 100644 --- a/tests/js/src/test/scala/coursier/test/JsTests.scala +++ b/tests/js/src/test/scala/coursier/test/JsTests.scala @@ -31,10 +31,10 @@ object JsTests extends TestSuite { assert(proj.parent == Some(Module("ch.qos.logback", "logback-parent"), "1.1.3")) } .run - .runF - .map{ res => + .map { res => assert(res.isRight) } + .future } } diff --git a/tests/js/src/test/scala/coursier/test/compatibility/package.scala b/tests/js/src/test/scala/coursier/test/compatibility/package.scala index 0f2c9b472..a96dfe9ed 100644 --- a/tests/js/src/test/scala/coursier/test/compatibility/package.scala +++ b/tests/js/src/test/scala/coursier/test/compatibility/package.scala @@ -1,7 +1,7 @@ package coursier.test -import coursier.util.{EitherT, TestEscape} -import coursier.{Fetch, Task} +import coursier.util.{EitherT, Task, TestEscape} +import coursier.Fetch import scala.concurrent.{ExecutionContext, Future, Promise} import scala.scalajs.js diff --git a/tests/jvm/src/test/scala/coursier/Platform.scala b/tests/jvm/src/test/scala/coursier/Platform.scala index a53b2c3df..2ba60cc1a 100644 --- a/tests/jvm/src/test/scala/coursier/Platform.scala +++ b/tests/jvm/src/test/scala/coursier/Platform.scala @@ -3,11 +3,9 @@ package coursier import java.io._ import java.nio.charset.StandardCharsets.UTF_8 -import coursier.interop.scalaz._ -import coursier.util.EitherT +import coursier.util.{EitherT, Task} import scala.util.{Failure, Success, Try} -import scalaz.concurrent.Task object Platform { @@ -26,7 +24,7 @@ object Platform { } def readFully(is: => InputStream): Task[Either[String, String]] = - Task { + Task.delay { val t = Try { val is0 = is val b = diff --git a/tests/jvm/src/test/scala/coursier/test/compatibility/package.scala b/tests/jvm/src/test/scala/coursier/test/compatibility/package.scala index 567505275..2f3c27fb3 100644 --- a/tests/jvm/src/test/scala/coursier/test/compatibility/package.scala +++ b/tests/jvm/src/test/scala/coursier/test/compatibility/package.scala @@ -3,21 +3,15 @@ package coursier.test import java.nio.charset.StandardCharsets.UTF_8 import java.nio.file.{Files, Paths} -import coursier.interop.scalaz._ -import coursier.util.{EitherT, TestEscape} +import coursier.util.{EitherT, Task, TestEscape} import coursier.{Cache, Fetch, Platform} import scala.concurrent.{ExecutionContext, Future} -import scalaz.concurrent.Task package object compatibility { implicit val executionContext = scala.concurrent.ExecutionContext.global - implicit class TaskExtensions[T](val underlying: Task[T]) extends AnyVal { - def runF: Future[T] = Future.successful(underlying.unsafePerformSync) - } - def textResource(path: String)(implicit ec: ExecutionContext): Future[String] = Future { val res = Option(getClass.getClassLoader.getResource(path)).getOrElse { throw new Exception(s"Not found: resource $path") @@ -49,9 +43,9 @@ package object compatibility { val init = EitherT[Task, String, Unit] { if (Files.exists(path)) - Task.now(Right(())) + Task.point(Right(())) else if (fillChunks) - Task[Either[String, Unit]] { + Task.delay[Either[String, Unit]] { Files.createDirectories(path.getParent) def is() = Cache.urlConnection(artifact.url, artifact.authentication).getInputStream val b = Platform.readFullySync(is()) @@ -62,7 +56,7 @@ package object compatibility { Left(e.toString) } else - Task.now(Left(s"not found: $path")) + Task.point(Left(s"not found: $path")) } init.flatMap { _ => diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index d80b62a5a..0d33ea153 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -4,7 +4,6 @@ package test import utest._ import scala.async.Async.{async, await} -import coursier.interop.scalaz._ import coursier.MavenRepository import coursier.Platform.fetch import coursier.test.compatibility._ @@ -55,7 +54,7 @@ abstract class CentralTests extends TestSuite { res } - .runF + .future } def resolutionCheck( diff --git a/tests/shared/src/test/scala/coursier/test/ResolutionTests.scala b/tests/shared/src/test/scala/coursier/test/ResolutionTests.scala index b058dd7bf..e0cdcab0e 100644 --- a/tests/shared/src/test/scala/coursier/test/ResolutionTests.scala +++ b/tests/shared/src/test/scala/coursier/test/ResolutionTests.scala @@ -19,7 +19,7 @@ object ResolutionTests extends TestSuite { Resolution(deps, filter = filter, forceVersions = forceVersions) .process .run(Platform.fetch(repositories)) - .runF + .future implicit class ProjectOps(val p: Project) extends AnyVal { def kv: (ModuleVersion, (Artifact.Source, Project)) = p.moduleVersion -> (testRepository.source, p) diff --git a/web/src/main/scala/coursier/web/Backend.scala b/web/src/main/scala/coursier/web/Backend.scala index 0573bda17..1f6fe9890 100644 --- a/web/src/main/scala/coursier/web/Backend.scala +++ b/web/src/main/scala/coursier/web/Backend.scala @@ -1,8 +1,8 @@ -package coursier -package web +package coursier.web +import coursier.{Dependency, Fetch, MavenRepository, Module, Platform, Repository, Resolution} import coursier.maven.MavenSource - +import coursier.util.{Gather, Task} import japgolly.scalajs.react.vdom.{ TagMod, Attr } import japgolly.scalajs.react.vdom.Attrs.dangerouslySetInnerHtml import japgolly.scalajs.react.{ ReactEventI, ReactComponentB, BackendScope } @@ -34,11 +34,11 @@ final case class State( class Backend($: BackendScope[Unit, State]) { def fetch( - repositories: Seq[core.Repository], + repositories: Seq[Repository], fetch: Fetch.Content[Task] ): Fetch.Metadata[Task] = { - modVers => Task.gatherUnordered( + modVers => Gather[Task].gather( modVers.map { case (module, version) => Fetch.find(repositories, module, version, fetch) .run @@ -112,8 +112,8 @@ class Backend($: BackendScope[Unit, State]) { .get(dep.moduleVersion) .toSeq .flatMap{case (_, proj) => - core.Resolution.finalDependencies(dep, proj) - .filter(resolution.filter getOrElse core.Resolution.defaultFilter) + coursier.core.Resolution.finalDependencies(dep, proj) + .filter(resolution.filter getOrElse coursier.core.Resolution.defaultFilter) } val minDependencies = resolution.minDependencies @@ -185,7 +185,7 @@ class Backend($: BackendScope[Unit, State]) { // For reasons that are unclear to me, not delaying this when using the runNow execution context // somehow discards the $.modState above. (Not a major problem as queue is used by default.) - Future(task)(scala.scalajs.concurrent.JSExecutionContext.Implicits.queue).flatMap(_.runF).foreach { res: Resolution => + Future(task)(scala.scalajs.concurrent.JSExecutionContext.Implicits.queue).flatMap(_.future).foreach { res: Resolution => $.modState{ s => updateDepGraph(res) updateTree(res, "#deptree", reverse = s.reverseTree)