class UpperCaser: in_lines = flowbase.Port() out_lines = flowbase.Port() async def run(self): while not self.in_lines.empty(): s = await self.in_lines.get() await self.out_lines.put(s.upper())
class StringJoiner: in_leftpart = flowbase.Port() in_rightpart = flowbase.Port() out_lines = flowbase.Port() async def run(self): while not self.in_leftpart.empty() or not self.in_rightpart.empty(): leftpart = await self.in_leftpart.get() rightpart = await self.in_rightpart.get() await self.out_lines.put(f"{leftpart}{rightpart}")
class StringSplitter: in_lines = flowbase.Port() out_leftpart = flowbase.Port() out_rightpart = flowbase.Port() async def run(self): while not self.in_lines.empty(): s = await self.in_lines.get() await self.out_leftpart.put(s[:int(len(s) / 2)]) await self.out_rightpart.put(s[int(len(s) / 2):])
class Printer: in_lines = flowbase.Port() async def run(self): while not self.in_lines.empty(): s = await self.in_lines.get() print(f"Printer got line: {s}")
class HiSayer: out_lines = flowbase.Port() async def run(self): for i in range(20): await self.out_lines.put(f"Hi hi for the {i+1}:th time...")