diff --git a/.gitignore b/.gitignore index c0c6530..067645e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target/ .classpath .project .idea/ +/.metals/ diff --git a/build.sbt b/build.sbt index 608a10b..1679f9e 100644 --- a/build.sbt +++ b/build.sbt @@ -2,15 +2,22 @@ name := "scala-frp" organization := "io.dylemma" -version := "1.3" +version := "1.4" -crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0") +scalaVersion := "2.13.16" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test" +crossScalaVersions := Seq("2.13.16", "3.3.5") -scalacOptions in Compile += "-deprecation" +libraryDependencies ++= Seq( + "org.scala-lang.modules" %% "scala-parallel-collections" % "1.2.0", + "org.scalatest" %% "scalatest" % "3.2.19" % Test, +) + + +Compile / scalacOptions += "-deprecation" + +Compile / doc / scalacOptions += "-implicits" -scalacOptions in (Compile, doc) += "-implicits" // publishing stuff below @@ -24,12 +31,12 @@ publishTo := { Some("releases" at nexus + "service/local/staging/deploy/maven2") } -publishArtifact in Test := false +Test / publishArtifact := false pomIncludeRepository := { _ => false } pomExtra := ( -https://github.com/dylemma/scala.frp + https://github.com/dylemma/scala.frp MIT License diff --git a/project/build.properties b/project/build.properties index b168a33..0a832a2 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.13 +sbt.version=1.10.7 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 5d09f54..1d4f162 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") diff --git a/src/main/scala/io/dylemma/frp/EventJoin.scala b/src/main/scala/io/dylemma/frp/EventJoin.scala index ac50b57..08426e3 100644 --- a/src/main/scala/io/dylemma/frp/EventJoin.scala +++ b/src/main/scala/io/dylemma/frp/EventJoin.scala @@ -52,11 +52,11 @@ trait EventJoin[A, B, C] extends EventSource[C] { /** This is needed so that the respective closure is not * garbage-collected. */ - protected lazy val leftHandlerFunc = { e: Event[A] => handle(Left(e)) } + protected lazy val leftHandlerFunc = { (e: Event[A]) => handle(Left(e)) } /** This is needed so that the respective closure is not * garbage-collected. */ - protected lazy val rightHandlerFunc = { e: Event[B] => handle(Right(e)) } + protected lazy val rightHandlerFunc = { (e: Event[B]) => handle(Right(e)) } /** Checks whether both parent streams are stopped. * @return `true` if and only if both the `leftParent` and diff --git a/src/main/scala/io/dylemma/frp/EventSource.scala b/src/main/scala/io/dylemma/frp/EventSource.scala index 08965fd..01afa0b 100644 --- a/src/main/scala/io/dylemma/frp/EventSource.scala +++ b/src/main/scala/io/dylemma/frp/EventSource.scala @@ -40,7 +40,7 @@ trait EventSource[A] extends EventStream[A] with EventSourceImpl[A] { */ protected def purgeThreshold: Int = 5 - private var refs = new ParHashSet[WeakReference[Event[A] => Boolean]] + private var refs = new ParHashSet[WeakReference[Event[A] => Boolean]]() private[frp] def addHandler(handler: Event[A] => Boolean): Unit = { refs += new WeakReference(handler) diff --git a/src/main/scala/io/dylemma/frp/impl/EventStreamCombinators.scala b/src/main/scala/io/dylemma/frp/impl/EventStreamCombinators.scala index 769a000..38e0541 100644 --- a/src/main/scala/io/dylemma/frp/impl/EventStreamCombinators.scala +++ b/src/main/scala/io/dylemma/frp/impl/EventStreamCombinators.scala @@ -262,7 +262,7 @@ private[frp] class DeadlinedEventStream[A](val parent: EventStream[A], deadline: case Stop => stop() false - case Fire(_) if deadline.isOverdue => + case Fire(_) if deadline.isOverdue() => stop() false case Fire(e) => @@ -345,8 +345,8 @@ private[frp] class GroupedEventStream[A](val parent: EventStream[A], val groupSi //how to fire the buffer (and clear it too) private def fireBuffer() = { if (buf.nonEmpty) { - val list = buf.result - buf.clear + val list = buf.result() + buf.clear() fire(list) } } diff --git a/src/main/scala/io/dylemma/frp/impl/TimeBasedFutures.scala b/src/main/scala/io/dylemma/frp/impl/TimeBasedFutures.scala index a449d8d..a029392 100644 --- a/src/main/scala/io/dylemma/frp/impl/TimeBasedFutures.scala +++ b/src/main/scala/io/dylemma/frp/impl/TimeBasedFutures.scala @@ -19,7 +19,7 @@ private [frp] object TimeBasedFutures { lazy val executor = Executors.newSingleThreadScheduledExecutor(DaemonThreadFactory) class PromiseCompletingRunnable[T](body: => T) extends Runnable { - val promise = Promise[T] + val promise = Promise[T]() override def run() = { promise complete { diff --git a/src/main/scala/io/dylemma/frp/package.scala b/src/main/scala/io/dylemma/frp/package.scala index 0e6fae6..a864a90 100644 --- a/src/main/scala/io/dylemma/frp/package.scala +++ b/src/main/scala/io/dylemma/frp/package.scala @@ -10,7 +10,7 @@ package object frp { * `System.currentTimeMillis`. */ implicit object SystemTime extends Time[Long] { - def currentTime = System.currentTimeMillis + def currentTime = System.currentTimeMillis() } implicit class EventStreamFutures[A](stream: EventStream[A]) { @@ -25,7 +25,7 @@ package object frp { def next(implicit obs: Observer): Future[A] = { if (stream.stopped) Future.failed(new NoSuchElementException("A stopped EventStream has no next event")) else { - val p = Promise[A] + val p = Promise[A]() stream sink { case Stop => p.failure(new NoSuchElementException("Stream stopped before firing any event")) @@ -47,7 +47,7 @@ package object frp { def last(implicit obs: Observer): Future[A] = { if (stream.stopped) Future.failed(new NoSuchElementException("Stream is already stopped")) else { - val p = Promise[A] + val p = Promise[A]() var latest: Try[A] = Failure(new NoSuchElementException("No event fired")) stream sink { case Stop => @@ -71,7 +71,7 @@ package object frp { def end[T](implicit obs: Observer, time: Time[T]): Future[T] = { if (stream.stopped) Future successful time.currentTime else { - val p = Promise[T] + val p = Promise[T]() stream onEnd { p success time.currentTime } p.future } diff --git a/src/test/scala/io/dylemma/frp/test/EventStreamDeadlineTests.scala b/src/test/scala/io/dylemma/frp/test/EventStreamDeadlineTests.scala index b669e06..99c6749 100644 --- a/src/test/scala/io/dylemma/frp/test/EventStreamDeadlineTests.scala +++ b/src/test/scala/io/dylemma/frp/test/EventStreamDeadlineTests.scala @@ -4,9 +4,11 @@ import io.dylemma.frp._ import org.scalatest._ import org.scalatest.concurrent.Waiters +import org.scalatest.funsuite.AnyFunSuite + import scala.concurrent.duration._ -class EventStreamDeadlineTests extends FunSuite with TestHelpers with Waiters with Observer { +class EventStreamDeadlineTests extends AnyFunSuite with TestHelpers with Waiters with Observer { test("EventStream.before only encounters events before the deadline") { val w = new Waiter @@ -21,7 +23,7 @@ class EventStreamDeadlineTests extends FunSuite with TestHelpers with Waiters wi s fire 3 s fire 4 assert(list.result == List(1, 2)) - w.dismiss + w.dismiss() } w.await() } @@ -51,7 +53,7 @@ class EventStreamDeadlineTests extends FunSuite with TestHelpers with Waiters wi s fire 3 s fire 4 assert(list.result == List(1, 2)) - w.dismiss + w.dismiss() } w.await() } @@ -68,7 +70,7 @@ class EventStreamDeadlineTests extends FunSuite with TestHelpers with Waiters wi s fire 3 s fire 4 assert(list.result == List(1, 2, 3, 4)) - w.dismiss + w.dismiss() } w.await() } diff --git a/src/test/scala/io/dylemma/frp/test/EventStreamFuturesTest.scala b/src/test/scala/io/dylemma/frp/test/EventStreamFuturesTest.scala index a3cc965..99436ed 100644 --- a/src/test/scala/io/dylemma/frp/test/EventStreamFuturesTest.scala +++ b/src/test/scala/io/dylemma/frp/test/EventStreamFuturesTest.scala @@ -5,16 +5,18 @@ import org.scalatest._ import org.scalatest.concurrent.Waiters import org.scalatest.exceptions.TestFailedException +import org.scalatest.funsuite.AnyFunSuite + import scala.concurrent.ExecutionContext.Implicits.global import scala.util.{Failure, Success} -class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with Observer { +class EventStreamFuturesTest extends AnyFunSuite with TestHelpers with Waiters with Observer { test("EventStream.next completes successfully when the stream fires an event") { val w = new Waiter val s = EventSource[Int]() - s.next foreach { case 5 => w.dismiss } + s.next foreach { case 5 => w.dismiss() } s fire 5 w.await(dismissals(1)) } @@ -25,7 +27,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with s.stop() // stream stopped before `next` is called s.next onComplete { - case Failure(_) => w.dismiss + case Failure(_) => w.dismiss() case Success(_) => } w.await(dismissals(1)) @@ -36,7 +38,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val s = EventSource[Int]() s.next onComplete { - case Failure(_) => w.dismiss + case Failure(_) => w.dismiss() case Success(_) => } s.stop() // stream stopped after `next` is called @@ -51,7 +53,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with s.next onComplete { case _ => fail("Future was expected to never complete") - w.dismiss + w.dismiss() } //await should time out, causing a failure. expect and intercept that failure @@ -64,7 +66,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val w = new Waiter val s = EventSource[Int]() - s.last foreach { case 3 => w.dismiss } + s.last foreach { case 3 => w.dismiss() } s fire 1 s fire 2 s fire 3 @@ -77,7 +79,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val w = new Waiter val s = EventSource[Int]() - s.last foreach { case 3 => w.dismiss } + s.last foreach { case 3 => w.dismiss() } s fire 1 s fire 2 s fire 3 @@ -94,7 +96,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with s.stop() s.last onComplete { - case Failure(_) => w.dismiss + case Failure(_) => w.dismiss() case Success(_) => } w.await(dismissals(1)) @@ -105,7 +107,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val s = EventSource[Int]() s.last onComplete { - case Failure(_) => w.dismiss + case Failure(_) => w.dismiss() case Success(_) => } s.stop() @@ -117,7 +119,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val s = EventSource[Int]() s.stop() - s.end foreach { case _ => w.dismiss } + s.end foreach { case _ => w.dismiss() } w.await(dismissals(1)) } @@ -125,7 +127,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val w = new Waiter val s = EventSource[Int]() - s.end foreach { case _ => w.dismiss } + s.end foreach { case _ => w.dismiss() } s.stop() w.await(dismissals(1)) } @@ -134,7 +136,7 @@ class EventStreamFuturesTest extends FunSuite with TestHelpers with Waiters with val w = new Waiter val s = EventSource[Int]() - s.end onComplete { _ => w.dismiss } + s.end onComplete { _ => w.dismiss() } //not stopping s... intercept[TestFailedException] { w.await(dismissals(1)) diff --git a/src/test/scala/io/dylemma/frp/test/EventStreamSinkTests.scala b/src/test/scala/io/dylemma/frp/test/EventStreamSinkTests.scala index 87e06a5..d35eded 100644 --- a/src/test/scala/io/dylemma/frp/test/EventStreamSinkTests.scala +++ b/src/test/scala/io/dylemma/frp/test/EventStreamSinkTests.scala @@ -1,10 +1,11 @@ package io.dylemma.frp.test +import org.scalatest.funsuite.AnyFunSuite import org.scalatest._ import io.dylemma.frp._ import collection.mutable.ListBuffer -class EventStreamSinkTests extends FunSuite with Observer { +class EventStreamSinkTests extends AnyFunSuite with Observer { test("EventStream.onNext encounters *only* the next event") { val s = EventSource[Int]() diff --git a/src/test/scala/io/dylemma/frp/test/EventStreamTests.scala b/src/test/scala/io/dylemma/frp/test/EventStreamTests.scala index b62dd32..609ec21 100644 --- a/src/test/scala/io/dylemma/frp/test/EventStreamTests.scala +++ b/src/test/scala/io/dylemma/frp/test/EventStreamTests.scala @@ -3,7 +3,9 @@ package io.dylemma.frp.test import org.scalatest._ import io.dylemma.frp._ -class EventStreamTests extends FunSuite with TestHelpers { +import org.scalatest.funsuite.AnyFunSuite + +class EventStreamTests extends AnyFunSuite with TestHelpers { implicit object observer extends Observer diff --git a/src/test/scala/io/dylemma/frp/test/EventStream_flatMap.scala b/src/test/scala/io/dylemma/frp/test/EventStream_flatMap.scala index 7e94108..1b7cf8c 100644 --- a/src/test/scala/io/dylemma/frp/test/EventStream_flatMap.scala +++ b/src/test/scala/io/dylemma/frp/test/EventStream_flatMap.scala @@ -1,9 +1,10 @@ package io.dylemma.frp.test +import org.scalatest.funsuite.AnyFunSuite import org.scalatest._ import io.dylemma.frp._ -class EventStream_flatMap extends FunSuite with TestHelpers with Observer { +class EventStream_flatMap extends AnyFunSuite with TestHelpers with Observer { test("EventStream.flatMap basic functionality") { val s = EventSource[Int]()