async def start(local_token=None): if local_token is None: raise RuntimeError('please provide yandex token') flow = (Zeroconf('_yandexio._tcp.local.') >> Tee( Printer()) >> Applicator(zc_station_info) >> Applicator( lambda x: device_token(local_token, x), thread=True) >> Applicator(station_connect) >> Tee( Printer()) >> Alice(lambda: ainput())) await flow.start()
async def start(): flow = ( Ticker() >> Logger('before', logging.DEBUG) >> Counter() >> Tee(Filter(lambda x: x % 2) >> Logger('tee', logging.DEBUG) >> Null()) >> Applicator(lambda x: x * 2) >> Logger('after', logging.ERROR) >> Printer()) await flow.start()
async def start(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('239.255.255.250', 1900)) mreq = struct.pack('=4sl', socket.inet_aton('239.255.255.250'), socket.INADDR_ANY) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) flow = (Udp(sock=sock) >> Applicator(parser) >> Printer()) await flow.start()
async def test_printer(): stream = io.StringIO() await asyncio.wait( ( (List([1, 2, 3]) >> Printer(stream)).start(), asyncio.sleep(0.01), ), return_when=asyncio.FIRST_COMPLETED, ) # we need this magic because we do not have # proper cancellation of flows yet tasks = [] for task in asyncio.tasks.all_tasks(): if task is not asyncio.Task.current_task(): task.cancel() tasks.append(task) await asyncio.wait(tasks) assert stream.getvalue() == '1\n2\n3\n'
async def start(): flow = (Thread(functools.partial(shell_command, 'ls -l')) >> Applicator(lambda x: x.decode().rstrip()) >> Printer()) await flow.start()
async def start(): udp = Udp(local_addr=('127.0.0.1', 5353), reuse_port=True) await (udp >> Tee(Printer()) >> udp).start()
async def start(): await (Ticker() >> Printer()).start()