import mpipe
import time

def echo(value):
    time.sleep(0.125)
    print(value)
    return True

pipe2 = mpipe.Pipeline(mpipe.OrderedStage(echo))

class Filter(mpipe.OrderedWorker):

    def __init__(self):
        self.count = 0

    def doTask(self, value):
        if self.count == 0:
            pipe2.put(value)
            self.count += 1

        elif self.count == 1:
            valid, result = pipe2.get(0.00001)
            if valid:
                self.putResult(result)
                self.count -= 1
            pipe2.put(value)
            self.count += 1

        elif self.count == 2:
            valid, result = pipe2.get(0.00001)
            if valid:
                self.putResult(result)
                pipe2.put(value)
                valid, result = pipe2.get(0.00001)
                if valid:
                    self.putResult(result)
                    self.count -= 1

pipe1 = mpipe.Pipeline(mpipe.Stage(Filter))

for number in range(10000):
    time.sleep(0.001)
    pipe1.put(number)

pipe1.put(None)
pipe2.put(None)

for result in pipe1.results():
    pass

from mpipe import OrderedStage, FilterStage, Pipeline
import time

def echo(value):
    print(value)
    time.sleep(0.0125)
    return value

pipe1 = Pipeline(OrderedStage(echo))
pipe2 = Pipeline(FilterStage(pipe1))

def pull(task):
    for result in pipe2.results():
        pass
pipe3 = Pipeline(OrderedStage(pull))
pipe3.put(True)

for number in range(10):
    pipe2.put(number)
    time.sleep(0.0100)

pipe1.put(None)
pipe2.put(None)
pipe3.put(None)

Update packetdrop test to use FilterStage class.