Advertisement
Guest User

Untitled

a guest
Mar 8th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.66 KB | None | 0 0
  1. import std.stdio;
  2. import std.concurrency;
  3.  
  4. class CustomMsg
  5. {
  6. private:
  7.     immutable this()
  8.     {
  9.     }
  10.  
  11. public:
  12.     static immutable(CustomMsg) create()
  13.     {
  14.         auto msg = new immutable(CustomMsg)();
  15.         return msg;
  16.     }
  17.  
  18. }
  19.  
  20. void main()
  21. {
  22.  
  23.     auto testThread = spawn({
  24.  
  25.         bool terminated = false;
  26.  
  27.         while (!terminated)
  28.         {
  29.  
  30.             try
  31.             {
  32.  
  33.                 receive
  34.                 (
  35.                     (immutable(CustomMsg) msg) { writeln("Received custom message"); },
  36.                     (OwnerTerminated ot) { writeln("Terminated"); terminated = true; }
  37.                 );
  38.  
  39.             }
  40.             catch(Throwable t)
  41.             {
  42.                 writeln(t.toString());
  43.             }
  44.  
  45.         }
  46.  
  47.     });
  48.  
  49.     auto msg = CustomMsg.create();
  50.     testThread.send(msg);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement