Comments (3)
I created my own helper class, turned out it wasn't too difficult :) I've posted the code below. Probably not conformant to your operator API, but fine for my needs ATM.
from aioreactive import AsyncAnonymousObserver
from aioreactive.subject import AsyncSubject
from asyncinit import asyncinit # External package
from .utils import dropargs # Wrapper function which drops arguments
@asyncinit
class BufferOperator():
async def __init__(self, boundaries):
self.emitter = AsyncSubject()
self.buffer = []
async def emit_buffer():
buffer = self.buffer
self.buffer = []
await self.emitter.asend(buffer)
self.subs = [
await boundaries.subscribe_async(AsyncAnonymousObserver(dropargs(emit_buffer)))
]
async def __call__(self, receiver):
async def add_to_buffer(x):
self.buffer.append(x)
self.subs.append(await receiver.subscribe_async(AsyncAnonymousObserver(add_to_buffer)))
return self
async def subscribe_async(self, *args, **kwargs):
return await self.emitter.subscribe_async(*args, **kwargs)
async def dispose_async(self):
for sub in self.subs:
await sub.dispose_async()
self.buffer.clear()
async def buffer(boundaries):
return await BufferOperator(boundaries)
# Used as follows:
values = AsyncSubject()
boundaries = AsyncSubject()
grouped_values = await pipe(
values,
await buffer(boundaries)
)
# Then grouped_values can be subscribed to.
from aioreactive.
Thanks. I'll have a look and see if I can re-use it!
from aioreactive.
I just came across this while looking for buffer
functions (specifically rx.operators.buffer_with_time_or_count
) for aioreactive.
Would be nice to have buffer parity with rxpy
, but sadly I am not (currently) smart enough to write it...
from aioreactive.
Related Issues (20)
- My first AsyncObservable HOT 1
- How can I install this? HOT 3
- Is this project still supported, or has functionality been migrated to RXPY 3.0? HOT 1
- Is this project abandoned? HOT 7
- README unclear HOT 1
- Observable from an async_generator? HOT 1
- Implementing reduce HOT 3
- Error example autocomplete , web.Application instance initialized with different loop HOT 1
- rx.delay frequently destroys tasks HOT 1
- AttributeError: 'NoneType' object has no attribute 'subscribe_async' in aioreactive/combine.py", line 99, in update HOT 1
- split.py example fails with InvalidStateError HOT 1
- Latest release?
- Python 3.11 support? HOT 11
- ImportError: cannot import name 'match' from 'expression.core' HOT 1
- Thank you for making this lib's type hinting so clean
- AsyncRx.distinct_until_changed, wrong signature HOT 2
- distinct_until_changed, not so nice signature? HOT 1
- feature request: optional comparer argument to distinct_until_changed
- AsyncIteratorObserver takes constructor arguments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aioreactive.