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)

Code Snippet

cd.State state = null;

yieldreturnArbiter.Choice(

_contractDirectory.Get(),

delegate(cd.State res) { state = res; },

delegate(Fault f) { LogInfo(f); }

);

if (state == null)

{

yield break;

}

New way:

Code Snippet

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

[5243 byte] By [GeorgeChrysanthakopoulos] at [2008-2-26]
# 1
Hi George,

This looks really handy, but you should be aware that there seems to have been a mix up with the tutorials.

In DSS Tutorial 6 [1] it talks as if this syntax is already available in MSRS 1.5, with the normal syntax mentioned in Appendix B as a way "which may be more familiar".

Perhaps the tutorial should be put back to the normal syntax until the next version of DSS ships.

Cheers,

James

[1] http://msdn2.microsoft.com/en-us/library/bb483058.aspx

JamesChaldecott(OXINST) at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 2
good catch, thank you
GeorgeChrysanthakopoulos at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...

Microsoft Robotics Studio

Site Classified