基于生成器的异步迭代算子

aiostream的Python项目详细描述


用于异步迭代的基于生成器的运算符

概要

aiostream提供了一组流运算符,可以组合这些运算符来创建 异步操作管道。

它可以看作是itertools的异步版本,尽管有些方面略有不同。 实际上,所有提供的运算符都返回一个称为流的统一接口。 流是增强的异步Iterable,提供以下功能:

  • 操作员管道内衬-使用管道符号|
  • 可重复性-每次迭代都创建不同的迭代器
  • 安全的迭代上下文-使用async withstream方法
  • 简化执行-使用await
  • 从流中获取最后一个元素 {STR 1 } $切片和索引< /强> -使用方括号^ {TT5}$
  • 连接-使用加法符号+

要求

流运算符严重依赖于异步生成器(PEP 525):

  • python=3.6

演示

下面的示例演示了大多数流功能:

importasynciofromaiostreamimportstream,pipeasyncdefmain():# Create a counting stream with a 0.2 seconds intervalxs=stream.count(interval=0.2)# Operators can be piped using '|'ys=xs|pipe.map(lambdax:x**2)# Streams can be slicedzs=ys[1:10:2]# Use a stream context for proper resource managementasyncwithzs.stream()asstreamer:# Asynchronous iterationasyncforzinstreamer:# Print 1, 9, 25, 49 and 81print('->',z)# Streams can be awaited and return the last valueprint('9² = ',awaitzs)# Streams can run several timesprint('9² = ',awaitzs)# Streams can be concatenatedone_two_three=stream.just(1)+stream.range(2,4)# Print [1, 2, 3]print(awaitstream.list(one_two_three))# Run main coroutineloop=asyncio.get_event_loop()loop.run_until_complete(main())loop.close()

文档的example section中提供了更多示例。

联系人

文森特·米歇尔:vxgmichel@gmail.com

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java log4j找不到log4jtest。房产?   我在java线程“awteventque1”中获得异常。lang.NullPointerException   java为什么在使用完整路径从文件系统读取文件时出错?   java如何迭代所有注册表项?   java中的安卓 Opencv SVM未正确训练   多线程Java ThreadPoolExecutor关闭特定线程?   如何使用Java NIO CreateDirectory方法设置目录所有者组?   java NatTable混合了固定宽度的列和可调整大小的填充剩余空间   java如何删除特定网络,即使该网络是由安卓上的其他设备创建的?   java Guava toJavaUtil()不存在   java对许多常量使用枚举是有效的memorywise?   java是否可以使用坐标定位JButton?   从WSDL生成java代码导致异常   java如何在安卓中导出javadoc   爬行JAX中的java NoClassDefFoundError错误   java为片段中的文本视图设置区域设置   发送最后一条消息后发生Java RMI RemoteException