added lesson 8
This commit is contained in:
parent
34b1ff39ce
commit
a16b70970f
19
src/Lesson8/Actors.scala
Normal file
19
src/Lesson8/Actors.scala
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package Lesson8
|
||||||
|
|
||||||
|
import akka.actor.{Actor, ActorSystem, Props}
|
||||||
|
|
||||||
|
object Actors extends App {
|
||||||
|
case class Greetings(who: String)
|
||||||
|
|
||||||
|
class SimplestActor extends Actor {
|
||||||
|
def receive = {
|
||||||
|
case Greetings(who) => println(s"Hello $who, pleased to meet you")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val system = ActorSystem("MySystem")
|
||||||
|
val simple_greeter = system.actorOf(Props[SimplestActor])
|
||||||
|
|
||||||
|
simple_greeter ! Greetings("Dr Who")
|
||||||
|
}
|
||||||
|
|
18
src/Lesson8/Futures.scala
Normal file
18
src/Lesson8/Futures.scala
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package Lesson8
|
||||||
|
|
||||||
|
import scala.concurrent.Future
|
||||||
|
import scala.util.{Failure, Success}
|
||||||
|
|
||||||
|
object Futures extends App {
|
||||||
|
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
|
||||||
|
|
||||||
|
val f: Future[Int] = Future {
|
||||||
|
Thread.sleep(650)
|
||||||
|
3 + 4
|
||||||
|
}
|
||||||
|
|
||||||
|
f onComplete {
|
||||||
|
case Success(x: Int) => println(s"Computing done, result is $x")
|
||||||
|
case Failure(ex) => println("Error")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user