Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.classpath
.project
.idea/
/.metals/
21 changes: 14 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,12 +31,12 @@ publishTo := {
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

publishArtifact in Test := false
Test / publishArtifact := false

pomIncludeRepository := { _ => false }

pomExtra := (
<url>https://github.com/dylemma/scala.frp</url>
<url>https://github.com/dylemma/scala.frp</url>
<licenses>
<license>
<name>MIT License</name>
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.13
sbt.version=1.10.7
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions src/main/scala/io/dylemma/frp/EventJoin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/dylemma/frp/EventSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/dylemma/frp/impl/TimeBasedFutures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/io/dylemma/frp/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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"))
Expand All @@ -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 =>
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down
26 changes: 14 additions & 12 deletions src/test/scala/io/dylemma/frp/test/EventStreamFuturesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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()
Expand All @@ -117,15 +119,15 @@ 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))
}

test("EventStream.end completes successfully when the stream stops") {
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))
}
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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]()
Expand Down
4 changes: 3 additions & 1 deletion src/test/scala/io/dylemma/frp/test/EventStreamTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/io/dylemma/frp/test/EventStream_flatMap.scala
Original file line number Diff line number Diff line change
@@ -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]()
Expand Down