Collect does not allow awaitable sinks

Closed
#468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start by locating the Python collect stream class and its flush method, then run the issue's awaitable-sink example. Check how flush propagates results to downstream sinks and compare that with regular synchronous sinks. Done means awaitable sinks complete correctly without breaking existing collection and flush behavior, with tests covering both cases.

Written by the indexing model from the issue text.

Description

The collect class does not allow for awaitable sinks.

Small example:

async def sink_to_something(x):
    print(x)
    return await asyncio.sleep(1)

source = streamz.Source()
collector = source.collect()
collector.sink(sink_to_something)

for i in range(10):
    source.emit(i)
    collector.flush()

Changing def flush in the collect class from:

@Stream.register_api()
class collect(Stream):
    ...
    def flush(self, _=None):
        out = tuple(self.cache)
        metadata = list(self.metadata_cache)
        self._emit(out, metadata)
        ...

To:

@Stream.register_api()
class collect(Stream):
    ...
    def flush(self, _=None):
        out = tuple(self.cache)
        metadata = list(self.metadata_cache)
        # change self._emit to self.emit (self.emit waits for awaitable results from downstream)
        self.emit(out, metadata=metadata)
        ...

Fixed this problem, but I'm not sure if this has any drawbacks.

Dominant language
Python
Stars
1.3k
Forks
149
Avg merge
17h 39m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-streamz/streamz

All issues in python-streamz/streamz

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.