Skip to content

Instantly share code, notes, and snippets.

@banshee
Created April 6, 2013 23:55
Show Gist options
  • Save banshee/5328177 to your computer and use it in GitHub Desktop.
Save banshee/5328177 to your computer and use it in GitHub Desktop.
bob and alice for typed channels
package com.restphone
import akka.actor.Actor
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import akka.channels._
class Message
class Response
class Alice extends Actor with Channels[TNil, (Message, Response) :+: TNil] {
channel[Message] {
case (a, b) =>
println(f"alice: $a $b")
b <-!- (new Response)
}
}
class Bob extends Actor with Channels[TNil, (Response, Nothing) :+: TNil]
// If you delete these lines (through XXX), you'll see the println from alice.
// If you include these lines, you'll see
// [ERROR] [04/06/2013 16:46:43.400] [MySystem-akka.actor.default-dispatcher-4] [akka://MySystem/user/bob] missing declarations for channels akka.channels.:+:[(com.restphone.Response, Nothing),akka.channels.TNil]
{
channel[Response] {
case (a, b) => println(f"bob: $a $b")
}
}
// XXX
object MyApp extends App {
val customConf = ConfigFactory.parseString("""
akka {
loglevel = "DEBUG"
}
""")
val system = ActorSystem("MySystem", ConfigFactory.load(customConf))
val alice = ChannelExt(system).actorOf(new Alice(), "alice")
implicit val bob = ChannelExt(system).actorOf(new Bob(), "bob")
(new Message) -!-> alice
Thread.sleep(2000)
system.shutdown
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment