Dispatching from receive to a function
Bob Cowdery
bob at bobcowdery.plus.com
Mon Sep 27 06:07:15 PDT 2010
I've been looking for a way to hook up messages to a thread with a
handler function. As far as I can tell receive pattern matching only
allows the pattern to be distinguished by the parameter signature which
does not help when all the handlers only have a few different signatures.
I like the pattern matching concept as I have worked with Erlang which
will pattern match to a term (basically an arbitrary structure). Erlang
defines an Atom type which is really a global constant that can be used
as a message type in the match. Does anyone know of a way to simulate this?
Failing that I think a dispatcher structure using an associative array
would be my next choice. However I'm getting stuck on how to define and
use an array which maps a string key to a delegate. Can someone help me
out there please. I will then effectively have my 'Atom' as a string in
the message and dispatch on that.
I don't want to hard code in a switch statement.
Any other suggestions are very welcome.
Thanks
Bob
More information about the Digitalmars-d-learn
mailing list