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

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 IntelliJ找不到依赖项选项卡   java向字符串数组string[]添加元素并在Junit中测试结果   如何在eclipse中获取活动java项目的名称   如何使用java在mysql中插入时间   java ArrayList更新了插入一行,但Jtable仍然没有刷新   如何在JavaSwing中命名坐标(点)   java Matcher/模式不打印   java错误地设置了arraylist   使用UsernamePasswordCredential提供程序的java列表Azure AD   java在HTTP请求中设置UTC时间   未加载事件:jquery完整日历Java集成   java Maven插件依赖项无法从内部repo解析依赖项   Maven更新重置Java版本   java如何向中添加图片。带有Apache POI XWPF的docx,但不指定其大小   Java最大函数递归