Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let behavior swap be a first citizen. #61

Open
andreaTP opened this issue Nov 29, 2016 · 2 comments
Open

Let behavior swap be a first citizen. #61

andreaTP opened this issue Nov 29, 2016 · 2 comments

Comments

@andreaTP
Copy link

All the Typed API is really well defined and you have 2/3 of the Actor model semantics already available:

  • spawn new (re)actors
  • passing messages between (re)actors

the missing point IMO is

  • a (re)actor could change it's behavior

Talking with @axel22 he said that there are alternatives to have this, but I'd like to have it as a first class API from the library.

WDYT?

@axel22
Copy link
Member

axel22 commented Jan 3, 2017

Hi @andreaTP !

Seems like that could be achieved something like this:

class BehaveReactor extends Reactor[String] { self =>
  def behave(f: String => Unit): Unit = {
    subscription.unsubscribe()
    self.main.events.onEvent(f)
  }
  def otherBehavior(s: String) = println("Second event: " + s)
  val subscription = self.main.events onEvent { x =>
    println("First event: " + x)
    behave(otherBehavior)
  }
}

val ch = system.spawn(Proto[BehaveReactor])
ch ! "Hello"
ch ! "World!"

Is that what you had in mind?

@andreaTP
Copy link
Author

andreaTP commented Jan 6, 2017

Hi @axel22
thanks for the answer, this solves only partially the problem,

i.e. : what if I'm in the otherBehavior and I wanna dependently pass to a third one? for example if I receive "Uppercase" or "Lowercase" I will print messages as indicated from there on.
Describing it in within a behavior that can change again.

Hope this is clear...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants