mirror of https://github.com/sbt/sbt.git
Remove former JS-only coursier.Task
This commit is contained in:
parent
87e5f33754
commit
13eda41fa2
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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 { _ =>
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue