[dmd-concurrency] Pattern matching on message receives, error handling
Sean Kelly
sean at invisibleduck.org
Wed Jan 13 11:11:46 PST 2010
On Jan 13, 2010, at 11:06 AM, Kevin Bealer wrote:
>
> If I do this syntax:
>
> auto dg1 = void delegate(A x) { ... };
> auto dg2 = void delegate(B x) { ... };
>
> receive(dg1, dg2);
>
> Does this mean receive anything that matches dg1, and if nothing is found, receive anything that matches dg2? Or does it mean to take the first message in order that matches either one?
The latter. The implementation is basically this:
foreach( m; message ) {
foreach( f; function ) {
if( argsMatch( m, f ) ) {
f( m );
dequeue( m );
return;
}
}
}
For dynamic pattern matching, the if test would be:
if( argsMatch( m, f ) && f( m ) ) {
dequeue( m );
return;
}
More information about the dmd-concurrency
mailing list