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

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如何从servlet向所有登录用户发送数据   java为什么需要ScheduledExecutorService。shutdown()使用我100%的CPU吗?   用于计算ArrayList中重复项的java嵌套循环无法正常工作   如何获取使用audioinputstream java下载文件的进度   java Kurento复合网格记录   识别方法的java问题   java on Markerclick listener绘制路线并计算距离   java在API级别16上创建/生成R.id   java如何修复HQL查询中的“意外令牌”错误   Java创建损坏的ZIP文件   JavaGSON。如何将json对象转换为json数组?   java需要配置Spring安全性和Hibernate   Vowpal Wabbit的Java API?