Skip to content

Commit

Permalink
Upgrade to 2.11.4 and added travel build
Browse files Browse the repository at this point in the history
  • Loading branch information
pchiusano committed Dec 15, 2014
1 parent f24c4c0 commit 2d73741
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: scala
scala:
- 2.11.4
jdk:
- oraclejdk7
- openjdk7
32 changes: 16 additions & 16 deletions answers/src/main/scala/fpinscala/parallelism/Actor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
import java.util.concurrent.{Callable,ExecutorService}
import annotation.tailrec

/*
/*
* Implementation is taken from `scalaz` library, with only minor changes. See:
*
*
* https://github.com/scalaz/scalaz/blob/scalaz-seven/concurrent/src/main/scala/scalaz/concurrent/Actor.scala
*
*
* This code is copyright Andriy Plokhotnyuk, Runar Bjarnason, and other contributors,
* and is licensed using 3-clause BSD, see LICENSE file at:
*
*
* https://github.com/scalaz/scalaz/blob/scalaz-seven/etc/LICENCE
*/

Expand All @@ -36,7 +36,7 @@ import annotation.tailrec
* @param strategy Execution strategy, for example, a strategy that is backed by an `ExecutorService`
* @tparam A The type of messages accepted by this actor.
*/
final case class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throwable => Unit = throw(_)) {
final class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throwable => Unit = throw(_)) {
self =>

private val tail = new AtomicReference(new Node[A]())
Expand All @@ -56,7 +56,7 @@ final case class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throw
}

def contramap[B](f: B => A): Actor[B] =
Actor[B](strategy)((b: B) => (this ! f(b)), onError)
new Actor[B](strategy)((b: B) => (this ! f(b)), onError)

private def trySchedule() {
if (suspended.compareAndSet(1, 0)) schedule()
Expand Down Expand Up @@ -98,14 +98,14 @@ private class Node[A](var a: A = null.asInstanceOf[A]) extends AtomicReference[N
object Actor {

/** Create an `Actor` backed by the given `ExecutorService`. */
def apply[A](es: ExecutorService)(handler: A => Unit, onError: Throwable => Unit = throw(_)): Actor[A] =
Actor(Strategy.fromExecutorService(es))(handler, onError)
def apply[A](es: ExecutorService)(handler: A => Unit, onError: Throwable => Unit = throw(_)): Actor[A] =
new Actor(Strategy.fromExecutorService(es))(handler, onError)
}

/**
* Provides a function for evaluating expressions, possibly asynchronously.
* The `apply` function should typically begin evaluating its argument
* immediately. The returned thunk can be used to block until the resulting `A`
/**
* Provides a function for evaluating expressions, possibly asynchronously.
* The `apply` function should typically begin evaluating its argument
* immediately. The returned thunk can be used to block until the resulting `A`
* is available.
*/
trait Strategy {
Expand All @@ -114,18 +114,18 @@ trait Strategy {

object Strategy {

/**
/**
* We can create a `Strategy` from any `ExecutorService`. It's a little more
* convenient than submitting `Callable` objects directly.
* convenient than submitting `Callable` objects directly.
*/
def fromExecutorService(es: ExecutorService): Strategy = new Strategy {
def apply[A](a: => A): () => A = {
val f = es.submit { new Callable[A] { def call = a} }
val f = es.submit { new Callable[A] { def call = a} }
() => f.get
}
}

/**
/**
* A `Strategy` which begins executing its argument immediately in the calling thread.
*/
def sequential: Strategy = new Strategy {
Expand Down
33 changes: 17 additions & 16 deletions exercises/src/main/scala/fpinscala/parallelism/Actor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
import java.util.concurrent.{Callable,ExecutorService}
import annotation.tailrec

/*
/*
* Implementation is taken from `scalaz` library, with only minor changes. See:
*
*
* https://github.com/scalaz/scalaz/blob/scalaz-seven/concurrent/src/main/scala/scalaz/concurrent/Actor.scala
*
*
* This code is copyright Andriy Plokhotnyuk, Runar Bjarnason, and other contributors,
* and is licensed using 3-clause BSD, see LICENSE file at:
*
*
* https://github.com/scalaz/scalaz/blob/scalaz-seven/etc/LICENCE
*/

Expand All @@ -36,7 +36,7 @@ import annotation.tailrec
* @param strategy Execution strategy, for example, a strategy that is backed by an `ExecutorService`
* @tparam A The type of messages accepted by this actor.
*/
final case class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throwable => Unit = throw(_)) {
final class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throwable => Unit = throw(_)) {
self =>

private val tail = new AtomicReference(new Node[A]())
Expand All @@ -56,7 +56,7 @@ final case class Actor[A](strategy: Strategy)(handler: A => Unit, onError: Throw
}

def contramap[B](f: B => A): Actor[B] =
Actor[B](strategy)((b: B) => (this ! f(b)), onError)
new Actor[B](strategy)((b: B) => (this ! f(b)), onError)

private def trySchedule() {
if (suspended.compareAndSet(1, 0)) schedule()
Expand Down Expand Up @@ -98,14 +98,14 @@ private class Node[A](var a: A = null.asInstanceOf[A]) extends AtomicReference[N
object Actor {

/** Create an `Actor` backed by the given `ExecutorService`. */
def apply[A](es: ExecutorService)(handler: A => Unit, onError: Throwable => Unit = throw(_)): Actor[A] =
Actor(Strategy.fromExecutorService(es))(handler, onError)
def apply[A](es: ExecutorService)(handler: A => Unit, onError: Throwable => Unit = throw(_)): Actor[A] =
new Actor(Strategy.fromExecutorService(es))(handler, onError)
}

/**
* Provides a function for evaluating expressions, possibly asynchronously.
* The `apply` function should typically begin evaluating its argument
* immediately. The returned thunk can be used to block until the resulting `A`
/**
* Provides a function for evaluating expressions, possibly asynchronously.
* The `apply` function should typically begin evaluating its argument
* immediately. The returned thunk can be used to block until the resulting `A`
* is available.
*/
trait Strategy {
Expand All @@ -114,18 +114,18 @@ trait Strategy {

object Strategy {

/**
/**
* We can create a `Strategy` from any `ExecutorService`. It's a little more
* convenient than submitting `Callable` objects directly.
* convenient than submitting `Callable` objects directly.
*/
def fromExecutorService(es: ExecutorService): Strategy = new Strategy {
def apply[A](a: => A): () => A = {
val f = es.submit { new Callable[A] { def call = a} }
val f = es.submit { new Callable[A] { def call = a} }
() => f.get
}
}

/**
/**
* A `Strategy` which begins executing its argument immediately in the calling thread.
*/
def sequential: Strategy = new Strategy {
Expand All @@ -135,3 +135,4 @@ object Strategy {
}
}
}

2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Keys._

object FPInScalaBuild extends Build {
val opts = Project.defaultSettings ++ Seq(
scalaVersion := "2.10.3",
scalaVersion := "2.11.4",
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)

Expand Down

0 comments on commit 2d73741

Please sign in to comment.