Created
January 8, 2014 22:55
-
-
Save sebnozzi/8326152 to your computer and use it in GitHub Desktop.
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
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