This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val behavior: Behavior[HumanCommand] = | |
Total { | |
case Eat(food) ⇒ | |
println(s"Tasty $food!") | |
Stopped | |
case Wait() ⇒ | |
Same | |
} | |
val log: PartialFunction[MessageOrSignal[HumanCommand], Unit] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val partial: PartialFunction[HumanCommand, Behavior[HumanCommand]] = { | |
case Eat(food) ⇒ | |
println(s"Tasty $food!") | |
Stopped | |
case Wait() ⇒ | |
Same | |
} | |
val behavior: Behavior[HumanCommand] = | |
Partial(partial) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sessions = List.empty[ActorRef[SessionEvent]] | |
Static { | |
case GetSession(screenName, client) ⇒ | |
sessions ::= client | |
client ! SessionGranted(ctx.self) | |
case PostSessionMessage(screenName, message) ⇒ | |
val mp = MessagePosted(screenName, message) | |
sessions foreach (_ ! mp) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Full { | |
case Sig(ctx, PreStart) ⇒ | |
val chatRoom = ctx.spawn(Props(ChatRoom.behavior), "chatroom") | |
val gabblerRef = ctx.spawn(Props(gabbler), "gabbler") | |
ctx.watch(gabblerRef) | |
chatRoom ! GetSession("ol’ Gabbler", gabblerRef) | |
Same | |
case Sig(_, Terminated(ref)) ⇒ | |
Stopped | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SelfAware[Command] { self ⇒ | |
Static { | |
case FoodOrdered(replyTo, order) ⇒ | |
val path = self.path | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ContextAware[Command] { ctx ⇒ | |
Static { | |
case FoodOrdered(replyTo, order) ⇒ | |
val frige = ctx.spawn(Props(Fridge.behavior), "frige") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def behavior(food : Set[Food], shopActor: ActorRef[ShopCommand]): Behavior[FoodOrdered] = //[1] | |
ContextAware[FridgeCommand] { ctx ⇒ | |
Total { | |
case FoodOrdered(replyTo, order) ⇒ | |
val f = food.find(_ == order) | |
replyTo ! f.map(food => Eat(food)).getOrElse(Wait(ctx.self)) | |
val wrapper = ctx.spawnAdapter { //[2] | |
n: NewFoodDelivered => StoreFood(n.food) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FridgeKey extends ServiceKey[FridgeCommand] | |
val receptionist: ActorRef[Receptionist.Command] = ctx.spawn(Props(Receptionist.behavior), "receptionist") | |
val human: ActorRef[Receptionist.Listing[FridgeCommand]] = _ | |
val fridge: ActorRef[Receptionist.Registered[FridgeCommand]] = _ | |
receptionist ! Register(key = FridgeKey, address = fridge)(replyTo = fridge) | |
receptionist ! Find(key = FridgeKey)(replyTo = human) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install node --with-npm | |
npm install -g yo | |
npm install -g generator-skinny |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir quick-poll && cd quick-poll/ | |
yo skinny |