Skip to content

Instantly share code, notes, and snippets.

@sebnozzi
Created January 8, 2014 22:55
Show Gist options
  • Save sebnozzi/8326152 to your computer and use it in GitHub Desktop.
Save sebnozzi/8326152 to your computer and use it in GitHub Desktop.
case class GreetingEvent(msg: String)
class Greeter extends Publisher[GreetingEvent] {
def greet(msg:String) = {
println("Firing event")
publish(GreetingEvent(msg))
}
}
class GreetingSubscriber(name: String)
extends Subscriber[GreetingEvent, Publisher[GreetingEvent]] {
override def notify(source: Publisher[GreetingEvent], event: GreetingEvent) {
println(s"$name received: ${event.msg}")
}
}
val greeter = new Greeter()
val s1 = new GreetingSubscriber("Subscriber 1")
val s2 = new GreetingSubscriber("Subscriber 2")
val s3 = new GreetingSubscriber("Subscriber 3")
Seq(s1, s2, s3).foreach(greeter.subscribe(_))
greeter.greet("Hello world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment