added lesson 8

This commit is contained in:
Louis Heredero 2025-05-05 17:08:21 +02:00
parent 34b1ff39ce
commit a16b70970f
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 37 additions and 0 deletions

19
src/Lesson8/Actors.scala Normal file
View 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
View 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")
}
}