Skip to content

Commit

Permalink
Enforce consistent arrow symbols using scalafmt (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterneyens authored Aug 18, 2017
1 parent 93a7d41 commit 49aaecb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ rewrite {
rules = [SortImports, RedundantBraces]
redundantBraces.maxLines = 1
}

rewriteTokens {
"⇒": "=>"
"←": "<-"
}
13 changes: 4 additions & 9 deletions shared/src/main/scala/implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,24 @@ object implicits {
override def runQuery[A](j: Query[A]): Future[A] = j match {

case Sync(e) =>
Future({e.value})
Future({ e.value })

case Async(ac, timeout) =>

val p = Promise[A]()

val runnable = new Runnable {
def run() : Unit = ac(p.trySuccess, p.tryFailure)
def run(): Unit = ac(p.trySuccess, p.tryFailure)
}

timeout match {

// Handle the case where there is a finite timeout requested
case finite: FiniteDuration =>

// Timer task that completes the future when the timeout occurs
// if it didn't complete already
val timerTask = new TimerTask() {
def run() : Unit = {
def run(): Unit =
p.tryFailure(new TimeoutException())
}
}

// Start the timeout Timer
Expand All @@ -61,9 +58,8 @@ object implicits {
// Execute the user's action
ec.execute(runnable)

// No timeout
// No timeout
case _ =>

// Execute the user's action
ec.execute(runnable)
}
Expand All @@ -74,6 +70,5 @@ object implicits {
runQuery(qf).zip(runQuery(qx)).map { case (f, x) => f(x) }
}


}
}
12 changes: 6 additions & 6 deletions twitter/jvm/src/main/scala/TwitterFuture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ object implicits {
): FetchMonadError[Rerunnable] =
new FetchMonadError.FromMonadError[Rerunnable] {
override def runQuery[A](j: Query[A]): Rerunnable[A] = j match {
case Sync(e) evalToRerunnable(e)
case Async(ac, timeout)
case Sync(e) => evalToRerunnable(e)
case Async(ac, timeout) =>
Rerunnable.fromFuture {
val p: Promise[A] = Promise()
pool(ac(p setValue _, p setException _))
Expand All @@ -48,7 +48,7 @@ object implicits {
case _ => p
}
}
case Ap(qf, qx)
case Ap(qf, qx) =>
runQuery(qf).product(runQuery(qx)) map { case (f, x) => f(x) }
}
}
Expand All @@ -58,16 +58,16 @@ object implicits {
): FetchMonadError[Future] =
new FetchMonadError.FromMonadError[Future] {
override def runQuery[A](j: Query[A]): Future[A] = j match {
case Sync(e) Future(e.value)
case Async(ac, timeout)
case Sync(e) => Future(e.value)
case Async(ac, timeout) =>
val p: Promise[A] = Promise()
pool(ac(p setValue _, p setException _))
timeout match {
case _: FiniteDuration =>
p.raiseWithin(Duration(timeout.length, timeout.unit))(Timer.Nil)
case _ => p
}
case Ap(qf, qx)
case Ap(qf, qx) =>
ap(runQuery(qf))(runQuery(qx))
}
}
Expand Down
12 changes: 6 additions & 6 deletions twitter/jvm/src/test/scala/FetchTwitterFutureSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FetchTwitterFutureSpec extends FlatSpec with Matchers {
object ArticleAsync extends DataSource[ArticleId, Article] {
override def name = "ArticleAsync"
override def fetchOne(id: ArticleId): Query[Option[Article]] =
Query.async((ok, fail) {
Query.async((ok, fail) => {
ok(Option(Article(id.id, "An article with id " + id.id)))
})
override def fetchMany(ids: NonEmptyList[ArticleId]): Query[Map[ArticleId, Article]] =
Expand All @@ -71,7 +71,7 @@ class FetchTwitterFutureSpec extends FlatSpec with Matchers {
implicit object AuthorFuture extends DataSource[AuthorId, Author] {
override def name = "AuthorFuture"
override def fetchOne(id: AuthorId): Query[Option[Author]] =
Query.async((ok, fail) {
Query.async((ok, fail) => {
ok(Option(Author(id.id, "@egg" + id.id)))
})
override def fetchMany(ids: NonEmptyList[AuthorId]): Query[Map[AuthorId, Author]] =
Expand All @@ -87,8 +87,8 @@ class FetchTwitterFutureSpec extends FlatSpec with Matchers {
}
it should "allow for several async datasources to be combined" in {
val fetch: Fetch[(Article, Author)] = for {
art article(1)
author author(art)
art <- article(1)
author <- author(art)
} yield (art, author)

Await.result(Fetch.run[Future](fetch), 100.milliseconds) shouldEqual (Article(
Expand Down Expand Up @@ -122,8 +122,8 @@ class FetchTwitterFutureSpec extends FlatSpec with Matchers {
}
it should "allow for several async datasources to be combined" in {
val fetch: Fetch[(Article, Author)] = for {
art article(1)
author author(art)
art <- article(1)
author <- author(art)
} yield (art, author)

val rr: Rerunnable[(Article, Author)] = Fetch.run[Rerunnable](fetch)
Expand Down

0 comments on commit 49aaecb

Please sign in to comment.