Skip to content

Instantly share code, notes, and snippets.

View pjazdzewski1990's full-sized avatar

Patryk Jażdżewski pjazdzewski1990

View GitHub Profile
val behavior: Behavior[HumanCommand] =
Total {
case Eat(food) ⇒
println(s"Tasty $food!")
Stopped
case Wait() ⇒
Same
}
val log: PartialFunction[MessageOrSignal[HumanCommand], Unit] = {
val partial: PartialFunction[HumanCommand, Behavior[HumanCommand]] = {
case Eat(food) ⇒
println(s"Tasty $food!")
Stopped
case Wait() ⇒
Same
}
val behavior: Behavior[HumanCommand] =
Partial(partial)
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)
}
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
}
SelfAware[Command] { self ⇒
Static {
case FoodOrdered(replyTo, order) ⇒
val path = self.path
}
}
ContextAware[Command] { ctx ⇒
Static {
case FoodOrdered(replyTo, order) ⇒
val frige = ctx.spawn(Props(Fridge.behavior), "frige")
}
}
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)
}
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)
brew install node --with-npm
npm install -g yo
npm install -g generator-skinny
mkdir quick-poll && cd quick-poll/
yo skinny