question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A method for combining streams

See original GitHub issue

One of the most common issues I see in new developers when they are trying to write a reddit bot is that they can’t figure out how to stream more than one thing. The two recommended solutions of either breaking after a certain number of requests to check the other stream, or using multiple processes are unintuitive and often end up causing the developer more problems than they solve.

An approach like this

subreddit = reddit.subreddit("redditdev")
for item in praw.models.util.stream_generator([subreddit.comments, subreddit.new]):
    if item.fullname.startswith("t3_"):
        print("New submission")
    elif item.fullname.startswith("t1_"):
        print("New comment")

would be much easier to use. It would require multiple api calls to fetch a new batch, but users would already be doing that anyway if they were using multiple streams, and streams generally don’t get any new items on the vast majority of their calls, so it’s unlikely to even be noticed.

It would require somewhat significantly reworking how streams work. It would need to store a before parameter per function, and the arguments attribute_name and exclude_before would need to be passed in differently. It would also need to fetch all the items for the streams and manually sort them to return them in the correct order.

It might be simpler to rework streams into their own class, similar to the proposal in #1025

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
zacccommented, Oct 3, 2020

@LilSpazJoekp and @Watchful1 , thanks for the feedback.

0reactions
github-actions[bot]commented, May 31, 2021

This issue was closed because it has been stale for 10 days with no activity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging Streams in Java - Baeldung
Learn the different ways of merging Java Streams. ... The simplest way to combine 2 Streams is to use the static Stream.concat() method:...
Read more >
How to merge many streams into one stream using Confluent
In this tutorial, learn how to merge many streams into one stream using Confluent, with step-by-step instructions and examples.
Read more >
Combine two streams and call method - java - Stack Overflow
If using Google Guava, you can do this to combine them: Streams.zip(users.stream(), workplaces.stream(), (user, workplace) -> mapping(user, ...
Read more >
Java 8 - Stream concat() method for merging elements
This Stream method creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements...
Read more >
Java 8 Stream concat() - HowToDoInJava
Learn to use Stream.concat() method is used to merge two streams into one stream which consist of all elements of both merged streams....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found