Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Callback(f: => Unit) {
- def apply() : Unit = f
- }
- trait CallbackHandler {
- self : Actor =>
- def handleCallback : Receive = {
- case callback: Callback =>
- callback()
- }
- override def unhandled(msg : Any) :Unit = {
- handleCallback.applyOrElse(msg, super.unhandled)
- }
- def onSuccess(fut: Future[T])(f : T => Unit) : Unit = {
- fut.onSuccess {
- t => self ! new Callback(f(t))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement