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

Event Based crap #1

Closed
vendethiel opened this issue Nov 6, 2013 · 19 comments
Closed

Event Based crap #1

vendethiel opened this issue Nov 6, 2013 · 19 comments

Comments

@vendethiel
Copy link
Contributor

Tight event-loop.

trait Event {
  type EventFuture = Future[Seq[Any]]
  val events: Seq[Symbol]
  val handlers = Map[Symbol, mutable.ListBuffer[() => Unit]]

  def subscribe(evt: Symbol, handler: () => Unit) {
    if (!events contains evt)
      throw new InvalidArgumentException(s"event $evt non existing")
    if (!handlers contains evt)
      handlers(evt) = mutable.ListBuffer[() => Unit]()

    handlers(evt) += handler
  }

  private def emit(evt: Symbol, o: Option[_] = None): EventFuture {
    ?
  }
}
class Character {
  def fightStart {
    fight = Fight(this)
    fight.subscribe('end, {someMethod()})
  }

  def someMethod {
  }
}
case class Fight(char: Character) extends Event {
  override val events = Seq('end)

  def onEnd { // called by some handler
    emit 'end
  }
}
@volgar1x
Copy link
Contributor

volgar1x commented Nov 6, 2013

How about this https://gist.github.com/Blackrush/7345399 but users have to pass an Executor to get emit asynchronous which is very odd

@vendethiel
Copy link
Contributor Author

C'est une implem. details qui leak :(.

@vendethiel
Copy link
Contributor Author

Et j'aime bien l'idée de check que c'est un event qui peut être emit même si sans compile time check c'est pas super utile

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Où ça ça leak ? Pour le check des events faudrait les définir avant d'emit

@vendethiel
Copy link
Contributor Author

implicit val executor = Executors.newSingleThreadExecutor()

la classe/l'objet devraient pas avoir à s'occuper de ça

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Ouais, d'où mon commentaire plus haut mais je doute qu'un seul Executor pour toute la VM fasse l'affaire

@vendethiel
Copy link
Contributor Author

Mettre sa création dans le constructeur d'Event ?

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Un Thread par Observable ? Bof bof

@vendethiel
Copy link
Contributor Author

:(. même faire un pool par type serait juste faire le devin ...

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

D'un autre côté, est-ce que c'est si important qu'emit soit asynchrone ?

@vendethiel
Copy link
Contributor Author

Your idea ;)

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Oui j'sais bien :D mais j'voulais savoir ton avis

@vendethiel
Copy link
Contributor Author

non je pense pas que ça soit très important, et au pire on peut faire un overload AsyncObservable plus tard si le besoin s'en fait sentir.

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Voilà c'est fait, j'ai ajouté une méthode 'emitted' pour marquer les events potentiellement déclenchés. J'commit des que j'ai un accès internet.

@vendethiel
Copy link
Contributor Author

k nice :).

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

Look b2c7a7c j'aime pas du tout Lid mais j'savais pas comment faire autrement.

@vendethiel
Copy link
Contributor Author

Pourquoi t'en as vraiment besoin ? Pourquoi def event = self ?

@volgar1x
Copy link
Contributor

volgar1x commented Nov 7, 2013

def event = self c'était dans l'ancienne API, Lid te permet d'unsubscribe un event. Je ne peux pas simplement me baser sur le hash de Listener qui peut changer (je pense notamment aux fonctions currifiées comme par exemple dans HandlerComponent.scala)

@vendethiel
Copy link
Contributor Author

oui j'ai bien répondu après :(.

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