真正异步的属性
aiopropert的Python项目详细描述
安装
pip3 install aioproperty
文件
您可以找到文档here
说明
aioproperty将异步getter和setter同时显示在一个位置。在
示例:
^{pr2}$aioproperty不是经典意义上的属性,它将值保存在asincio任务中。一次 如果您设置了一个新值,它将被安排在任务中。如果任何任务现在正在运行,它将等待直到它完成。 当你得到价值时,你实际上得到了一个当前的任务,你可以等待它来获得价值。 更重要的是:你不用等待就可以使用数学:
other=some_obj.hello+' byby'print(awaitother)
我们还介绍了链接:
classSomeClass:@aiopropertyasyncdefhello(self,value):awaitasyncio.sleep(1)returnvalue@hello.chainasyncdefsome_more(self,value):push_value(value)
链条就像减速器一样工作。它迭代地将每个函数应用于一个新值。它可以返回值或不返回任何值。
如果没有返回值,则值将保持为ASI。默认情况下,任何chained
函数都会插入到链的末尾,但是
您可以使用priority参数或is\u first参数来控制它。如果isu first为True,则它将插入
链的开始。在
您还可以使用我们的特殊装饰器inject
使用继承和修改固有属性:
classParent:@aiopropertyasyncdefhello(self,value):awaitasyncio.sleep(1)returnvalue@hello.chainasyncdefsome_more(self,value):push_value(value)classChild(Parent):@inject(Parent.hello,priority=100)asyncdefinjected_method(self,value):print('hello from injection')#another form of injection using name of a property@inject('hello')asyncdefinjected_method_2(self,value):print('hello from injection 2')
在我们的docs中阅读更多内容
- 项目
标签: