Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active December 17, 2015 02:38
Show Gist options
  • Save chris-martin/5536932 to your computer and use it in GitHub Desktop.
Save chris-martin/5536932 to your computer and use it in GitHub Desktop.
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