On Sun, 12 May 2013 03:39:23 GMT, punkUser wrote:

Hmm just updated to the latest snapshot and now ".acquire/release" won't compile on my ManualEvents... any ideas? Is there now a better way to implement the "wait on multiple objects" for broadcast functionality I'm currently doing with acquire/rawYield?

I made this change that removes the explicit ownership handling after some conversation with Vladimir Panteleev. A project that I'm working on finally convinced me that the explicit ownership model can get really involved up to a point where the advantages (mostly better avoidance of concurrecy bugs and the possibility to do low level trickery) start to lose all of their attraction. It also is consistent with how ordinary synchronous I/O works. Just "wait for multiple objects" now needs a different solution than using rawYield (which is a good thing, but this is still unresolved).

But together with this change it has become possible to read and write in parallel from different tasks. So a broadcasting facility could now be implemented similar to this (untested), using the new message passing facilities:

import vibe.core.concurrency;
import vibe.core.core;
import vibe.core.net;

struct Message { /*...*/ }
Message readMessage(InputStream str) { /*...*/ }

struct ConnInfo { Task readTask, writeTask; }
ConnInfo[] conns;

void onConnection(TCPConnection conn)
{
    ConnInfo ci;
    ci.readTask = runTask({
        while (!conn.empty) {
            auto msg = readMessage(conn);
            foreach (c; conns)
                if (c.readTask !is Task.getThis())
                    c.writeTask.send(msg);
        }
        ci.writeTask.interrupt(); // TODO: nicer shutdown
    });
    ci.writeTask = runTask({
        while (conn.connected) {
            receive((Message msg) {
                msg.writeOut(conn);
            });
        }
    });
    conns ~= ci;
}

My apologies for the breakage, it was unfortunately not avoidable in this case - but for the better, I think.