示例#1
0
    def __init__(self, producer_func, stages, consumer_func, validator=validate):
        '''constructs the pipeline'''
        self._validator = validator
        self._pipeline = consumer(consumer_func)

        while stages:
            self._pipeline = stage(stages.pop(), self._pipeline, self._validator)

        self._pipeline = Producer(producer_func, self._pipeline, self._validator)
示例#2
0
class Pipeline(object):

    def __init__(self, producer_func, stages, consumer_func, validator=validate):
        '''constructs the pipeline'''
        self._validator = validator
        self._pipeline = consumer(consumer_func)

        while stages:
            self._pipeline = stage(stages.pop(), self._pipeline, self._validator)

        self._pipeline = Producer(producer_func, self._pipeline, self._validator)

    def follow(self, initial_state):
        res = []
        try:
            while True:
                res.append(self._pipeline.send(initial_state))
        except StopIteration:
            self._pipeline.close()
            return res