This project is read-only.

Only one consumer at the time ?

Oct 9, 2007 at 10:39 AM
class Program
static Random r = new Random(0);
static Producer<Item> producer = new Producer<Item>();
static void Main(string[] args)
Consumer<Item> a = new Consumer<Item>(producer);
Consumer<Item> b = new Consumer<Item>(producer);

Utilities.Miscellaneous.Action action = CreateItem;
Worker w = new Worker(action, TimeSpan.Zero);

ConsumptionCycle<Item> cycle = new ConsumptionCycle<Item>(Foo);
a.Consume(cycle, "A");
b.Consume(cycle, "B");

static void CreateItem()
producer.Produce(new Item(r.Next(1000).ToString()));

static void Foo(IEnumerable<Item> items, object value)
foreach (Item i in items)
Console.WriteLine("Consumed by " + value.ToString());

The items are always consumed by A but what if I have 5 consumers and they treat the items differently ? It's impossible to do it with this utilities because it's based on IEnumerable and the yield keyword. Am I right ?