o id @s0ddlZddlZGdddZGdddZdS)Nc@sDeZdZdZefddZddZddZdefd d Z d d Z d S) IteratorPipezu Iterator Pipe creates an iterator that can be fed in data from another block of code or thread of execution cC t|_||_d|_d|_dSNF)queueQueue_q _sentinel_sentinel_pushed_closedselfsentinelr+/home/jon/h2ogpt/iterators/iterator_pipe.py__init__   zIteratorPipe.__init__cC|SNrr rrr__iter__zIteratorPipe.__iter__cCs0|jrt|jjdd}||jurd|_t|S)NT)block)r StopIterationrgetrr datarrr__next__s zIteratorPipe.__next__returncCs|jrdS|j|dS) Pushes next item to Iterator and returns True If iterator has been closed via close(), doesn't push anything and returns False FTr rputrrrrr s zIteratorPipe.putcCs|jsd|_|j|jdSz Close is idempotent. Calling close multiple times is safe Iterator will raise StopIteration only after all elements pushed before close have been iterated TNr rr rrrrrclose)szIteratorPipe.closeN) __name__ __module__ __qualname____doc__objectrrrboolr r#rrrrrs rc@s@eZdZefddZddZddZdefdd Zd d Z d S) AsyncIteratorPipecCrr)asynciorrrr r r rrrr6rzAsyncIteratorPipe.__init__cCrrrrrrr __aiter__<rzAsyncIteratorPipe.__aiter__cs4|jrt|jIdH}||jurd|_t|S)NT)r StopAsyncIterationrrrrrrr __anext__?s zAsyncIteratorPipe.__anext__rcs"|jrdS|j|IdHdS)rFNTrrrrrr Js zAsyncIteratorPipe.putcs*|jsd|_|j|jIdHdSdSr!r"rrrrr#Us zAsyncIteratorPipe.closeN) r$r%r&r(rr,r.r)r r#rrrrr*4s  r*)rr+rr*rrrrs/