View source code
Display the source code in std/concurrency.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.concurrency.receive
Receives a message from another thread.
Receive a message from another thread, or block if no messages of the specified types are available. This function works by pattern matching a message against a set of delegates and executing the first match found.
If a delegate that accepts a std.variant.Variant
is included as
the last argument to
, it will match any message that was not
matched by an earlier delegate. If more than one argument is sent,
the receive
Variant
will contain a std.typecons.Tuple
of all values
sent.
Prototype
void receive(T...)( T ops );
Example
import std.stdio; import std.variant; import std.concurrency; void spawnedFunction() { receive( (int i) { writeln("Received an int."); }, (float f) { writeln("Received a float."); }, (Variant v) { writeln("Received some other type."); } ); } void main() { auto tid = spawn(&spawnedFunction); send(tid, 42); }
Authors
Sean Kelly, Alex Rønne Petersen, Martin Nowak