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.

2.x: confused of method takeLast(long,TimeUnit)

See original GitHub issue

I’m a little confused about takeLast(long, TimeUnit). When executing the following code, each time the output order is supposed to be N digits in the last time window, but in fact the output results are inconsistent with the ideal state.

Code

 public static void main(String[] args) {
        ArrayList<Integer> ints = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            ints.add(i);
        }
        Observable.fromIterable(ints)
                .takeLast(1,TimeUnit.NANOSECONDS)
                .subscribe(longs->{
                    System.out.println(longs);
                });
        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

Result

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
akarnokdcommented, Sep 16, 2019

Because onComplete can happen much later than the previous onNext, thus that value is now out of the time window.

1reaction
FlyingPigQAQcommented, Sep 16, 2019

@akarnokd Hello! I would like to know that the takeLast() method is to get the data of the last window that was sent. We already got the data of the last window in the OnNext() method, so why do we have to make another time difference judgment in the onComplete() method

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxJava's takeLast method does not act as JavaDoc described
First of all, I guess your assumption would be 3 and 4 instead of 2 and 3 , given that there is also...
Read more >
TakeLast operator - ReactiveX
TakeLast. emit only the final n items emitted by an Observable. 1. 2 ... RxGroovy takeLast takeLastBuffer. takeLast ... RxJava 1․x takeLast takeLastBuffer....
Read more >
Enumerable.TakeLast<TSource>(IEnumerable<TSource ...
If count is not a positive number, this method returns an empty enumerable collection. Applies to. Product, Versions .NET, Core 2.0, Core 2.1,...
Read more >
takeLast - RxJS
takeLast results in an observable that will hold values up to count values in memory, until the source completes. It then pushes all...
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