nchannel

@property
shared(NChannel!(N, T))
nchannel
(
size_t N
T...
)
()

Examples

import std.concurrency;
import std.conv;

auto ch1 = channel!(int, long, string);
auto ch2 = channel!(int, long, string);

static void spawnFuncSender(shared ch1.Sender s)
{
    foreach(i; 0 .. 100){
        s.put(cast(int)i);
        s.put(i + (long.max >> 1) + 1);
        s.put(to!string(i));
    }
}


static void spawnFuncMiddle(shared ch1.Receiver r,
                            shared ch2.Sender s)
{
    foreach(i; 0 .. 100){
        foreach(E; TypeTuple!(int, long, string))
        {
            while(r.queue!E.empty){}
            s.put!E(*r.pop!E);
        }
    }
}

spawn(&spawnFuncSender, ch1.sender);
spawn(&spawnFuncMiddle, ch1.receiver,
                        ch2.sender);

foreach(i; 0 .. 100){
    foreach(E; TypeTuple!(int, long, string))
    {
        while(ch2.queue!E.empty){}

      static if(is(E == int))
        assert(*ch2.pop!E == i);
      else static if(is(E == long))
        assert(*ch2.pop!E == i + (long.max >> 1) + 1);
      else
        assert(*ch2.pop!E == i.to!string);
    }
}

Meta