REScala events don't fire.

Ankou
Mausschubser
Mausschubser
Beiträge: 85
Registriert: 15. Mai 2011 18:23

REScala events don't fire.

Beitrag von Ankou »

Hi, I have a problem using the REScala library.
Say I have an Event ev and register a function f to it via ev += f.
Now I call ev(x) twice in succession with different parameters but f is only called once.(It works when I replace the call of ev with a direct call of f)

Why is this the case?

salvaneschi
Mausschubser
Mausschubser
Beiträge: 49
Registriert: 29. Mär 2013 23:51

Re: REScala events don't fire.

Beitrag von salvaneschi »

can you post a minimal example ?

Ankou
Mausschubser
Mausschubser
Beiträge: 85
Registriert: 15. Mai 2011 18:23

Re: REScala events don't fire.

Beitrag von Ankou »

Code: Alles auswählen

object minimalExample extends App {
	val eventA = new ImperativeEvent[Unit]
	val eventB = new ImperativeEvent[Int]
	
	eventB += println
	
	//the following prints only 2
	eventA += (_ => eventB(1))
	eventA += (_ => eventB(2))
	
	//whereas this prints both (1 2):
	//eventA += (_ => println(1))
	//eventA += (_ => println(2))
	
	eventA()
}
I also just noticed that the output is 2 1 1 2 if all 4 lines are commented in, whereas it is 1 1 2 if all lines are commented in but in reverse order.

salvaneschi
Mausschubser
Mausschubser
Beiträge: 49
Registriert: 29. Mär 2013 23:51

Re: REScala events don't fire.

Beitrag von salvaneschi »

Good catch :)

Antworten

Zurück zu „Archiv“