std.concurrency: The fate of unmatched messages

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 10 16:39:30 PDT 2015


On Fri, 10 Jul 2015 19:39:24 +0000, E.S. Quinn wrote:

> the documentation i can find for std.concurrency mentions what happens
> when one receive() call gets a message it doesn't understand.

that `receive()` will not get such a message. `receive()` scans the whole 
mailbox to find the message it can process, and process only that, 
leaving other messages in mailbox.


> And if the latter, is there any way to actually give a single thread
> multiple mailboxes?

why do you want that? you can receive any message with `receive`, see the 
documentation[1]:

"If a delegate that accepts a std.variant.Variant is included as the last 
argument to receive, it will match any message that was not matched by an 
earlier delegate. If more than one argument is sent, the Variant will 
contain a std.typecons.Tuple of all values sent."

    receive(
        (int i) { writeln("Received an int."); },
        (float f) { writeln("Received a float."); },
        (Variant v) { writeln("Received some other type."); }
    );

this way your `receive` will get all messages. simply do nothing in 
`Variant` handler to drop messages you don't want to process.


[1] http://dlang.org/phobos/std_concurrency.html#.receive
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150710/7340fb6a/attachment.sig>


More information about the Digitalmars-d-learn mailing list