Skip to content

Instantly share code, notes, and snippets.

Avatar

Patryk Jażdżewski pjazdzewski1990

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