Beispiel #1
0
        /// <summary>
        /// Constructs an asynchronous producer with the given buffer size.
        /// </summary>
        /// <param name="sources">the source objects</param>
        /// <param name="func">the function mapping source objects to results</param>
        /// <param name="capacity">the size of the buffer</param>
        public AsyncProducer(IEnumerable <S> sources, ProducerFunction <S, T> func, int capacity)
        {
            _data = new T[capacity];
            _head = _tail = 0;                          // insert at tail, remove from head

            _full  = new Semaphore(0, capacity);        // 0 out of capacity full slots
            _empty = new Semaphore(capacity, capacity); // capacity out of capacity empty slots

            _sources = sources;
            _func    = func;

            // start async thread
            ThreadPool.QueueUserWorkItem(new WaitCallback(run));
        }
Beispiel #2
0
 /// <summary>
 /// Constructs an asynchronous producer with the default buffer size.
 /// </summary>
 /// <param name="sources">the source objects</param>
 /// <param name="func">the function mapping source objects to results</param>
 public AsyncProducer(IEnumerable <S> sources, ProducerFunction <S, T> func)
     : this(sources, func, DEFAULT_BUFFER_SIZE)
 {
     // calls the main constructor
 }