Last active
December 17, 2015 02:38
-
-
Save chris-martin/5536932 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import akka.actor._ | |
package object akkautil { | |
/** Switches the implicit `ActorContext`'s receive behavior to `behavior` | |
* until one message is handled, then returns to the previous behavior. | |
*/ | |
def temporarilyBecome(behavior: Actor.Receive)(implicit context: ActorContext) { | |
import context.unbecome | |
val become = context.become(_: Actor.Receive, discardOld = false) | |
become { | |
case m if behavior isDefinedAt m => | |
unbecome() | |
behavior(m) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment