www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14953] New: std.concurrency: Add function to flush message box


          Issue ID: 14953
           Summary: std.concurrency: Add function to flush message box
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: wendlec tcd.ie

This enhancement request was inspired by this thread:

http://forum.dlang.org/post/yavfidlhfohqfziqvkzr forum.dlang.org

The scenario:
A thread has several items in the message box, and the user wants to cancel not
just the current operation but flush the thread's message box, since the items
in the message box are no longer relevant.

The current behavior is that the thread insists on processing all items in the
message box. To suppress the thread from doing actual work, John Colvin
proposed this workaround:

void flushMailbox()
    bool r;
        r = receiveTimeout(Duration.zero, (Variant _){});
    } while(r);

In this way, the thread loops over each item in the message box, but does
nothing - until the message box is empty.

However, it would be more efficient to have a library function that empties the
message box immediately, instead of looping over the message box, cancelling
each item individually, before new input can be processed.

Aug 24 2015