[Issue 13916] Nested std.concurrency.receive doesn't work correctly

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13916

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P1  |P3

--


[Issue 13916] Nested std.concurrency.receive doesn't work correctly

2018-03-31 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13916

Seb  changed:

   What|Removed |Added

 CC||greensunn...@gmail.com

--- Comment #2 from Seb  ---
So I experimented with removing the message from the list before the handler is
called, but I always get a LinkTerminated Exception which comes from the child
being terminated.
The child is in a while(true) loop, so it shouldn't get terminated, but for
some reason now its module deconstructor is now immediately called :/


diff --git a/std/concurrency.d b/std/concurrency.d
index 0e1b505bc..1c426bcc0 100644
--- a/std/concurrency.d
+++ b/std/concurrency.d
@@ -1974,8 +1980,9 @@ private
 enum timedWait = false;
 }

-bool onStandardMsg(ref Message msg)
+bool onStandardMsg(ref Message msg, void delegate() beforeSuccess
= (){})
 {
 foreach (i, t; Ops)
 {
 alias Args = Parameters!(t);
@@ -1985,10 +1992,13 @@ private
 {
 static if (is(ReturnType!(t) == bool))
 {
-return msg.map(op);
+beforeSuccess();
+auto b = msg.map(op);
+return b;
 }
 else
 {
+beforeSuccess();
 msg.map(op);
 return true;
 }
@@ -2043,6 +2053,8 @@ private
 {
 for (auto range = list[]; !range.empty;)
 {
+import std.stdio;
+writefln("range: %s", range.front);
 // Only the message handler will throw, so if this occurs
 // we can be certain that the message was handled.
 scope (failure)
@@ -2071,11 +2083,9 @@ private
 }
 else
 {
-if (onStandardMsg(range.front))
-{
-list.removeAt(range);
+if (onStandardMsg(range.front, (){
list.removeAt(range); }))
 return true;
-}
+
 range.popFront();
 continue;
 }
```

--