Concise syntax for request response using implicit assignment operators
I have recently added some minor syntactic "sugar" that makes the common asynchronous request/response pattern very concise, especially in the context of iterators.
Below is a standard request/response, in a DSS service:
Old way :
(note the _contractDirectory.Get() is a helper that return PortSet)
cd.State state = null; yieldreturnArbiter.Choice( _contractDirectory.Get(), delegate(cd.State res) { state = res; }, delegate(Fault f) { LogInfo(f); } ); if (state == null) { yield break; }
cd.Get get; yieldreturn _contractDirectory.Get(out get); cd.Statestate = get.ResponsePort; if (state == null) { LogInfo((Fault)get.ResponsePort); }
Notice the following:
1)No need to specify delegates for each branch of choice. Just yield to a PortSet, a new implicit assignment operator creates a choice for each port in the portSet. When any message is posted, it re-posts the item back in the port set, and allows the iterator to continue
2) You can now read an item from a PortSet/Port by simply assigning to a variable, again using implicit assignment operator that calls PortSet.Test underneath
cd.Statestate = get.ResponsePort;
While this did not make 1.5, you can add helpers that do something very similar on CCR 1.5
g

