#1302 Coalescing of messages when using Future.get doesn't

msl Tue 9 Nov 2010

Another actor related one - not sure if this is a bug or a misunderstanding on my part:

using concurrent

const class Sample {
	Void main() {

		toKey := |Obj? o -> Obj?| { o }
		coalesce := |Obj? o, Obj? i -> Obj?| { "${o}+" }
		receive := |Obj? o -> Obj?| { Actor.sleep(250ms); echo(o); return o }

		a := Actor.makeCoalescing(ActorPool(), toKey, coalesce, receive)

		a.send("one")

		a.send("two")
		a.send("two")
		a.send("two")

		a.send("three").get
		a.send("three").get
		a.send("three").get

		Actor.sleep(2sec) 
	}
}

I'd expect the handling of "two" and "three" to be the same - however the coalesce function isn't called when concurrent::Future.get is included.

ivan Tue 9 Nov 2010

This happens because .get guarantees that message has been delivered and processed. The sys::Actor.makeCoalescing states:

If an incoming message has the same key as a pending message in the queue, then the coalesce function is called to coalesce the messages into a new merged message.

rosarinjroy Tue 9 Nov 2010

msl: get is a blocking call. So until the first a.send("three").get completes, the second a.send("three") is not invoked. Hence there is no two messages with the same key, and hence there is no need for coalescing. Thats why you are not seeing the coalesce function called.

Login or Signup to reply.