from homebrain import Agent, Event, Dispatcher

class Chunker(Agent):
    """Listens to a certain trigger event, and emits a target event once the specified count has been reached."""
    def __init__(self, count, target=None):
        Agent.__init__(self)
        self.target = target if target is not None else self.identifier
        self.count = count
        self.events = []

    def run(self):
        while True:
            event = self.next_event()
            self.events.append(event)
            if len(self.events) >= self.count:
                Dispatcher().post(Event(**{"type":self.target, "data": self.events}))
                self.events = []

@@ -15,16 +15,24 @@
  import 
+Conveyor
 Agent, E
@@ -49,16 +49,17 @@
 atcher%0A%0A
+%0A
 class Ch
@@ -64,16 +64,24 @@
 Chunker(
+Conveyor
 Agent):%0A
@@ -87,16 +87,21 @@
 %0A    %22%22%22
+%0A    
 Listens 
@@ -195,20 +195,26 @@
 reached.
+%0A    
 %22%22%22%0A
+%0A
     def 
@@ -257,21 +257,36 @@
         
-Agent
+super(Chunker, self)
 .__init_
@@ -287,20 +287,16 @@
 _init__(
-self
 )%0A      
@@ -422,85 +422,145 @@
     
-def run(self):%0A        while True:%0A            
+@ConveyorAgent.stop_on_shutdown_event%0A    @ConveyorAgent.log_events%0A    @ConveyorAgent.log_exceptions%0A    def handle_
 event
- = 
+(
 self
-.next_event()%0A    
+, event):%0A
     
@@ -597,20 +597,16 @@
         
-    
 if len(s
@@ -644,20 +644,16 @@
         
-   
- 
 Dispatch
@@ -662,16 +662,33 @@
 ().post(
+%0A                
 Event(**
@@ -695,16 +695,17 @@
 %7B%22type%22:
+ 
 self.tar
@@ -708,16 +708,41 @@
 .target,
+%0A                        
  %22data%22:
@@ -765,28 +765,24 @@
             
-    
 self.events 
@@ -766,28 +766,65 @@
            self.events = %5B%5D%0A
+%0A    def cleanup(self):%0A        pass%0A

converted Chunker into a ConveyorAgent