Skip to content

[1.2.6] throttleFirst doesn't emit item if user changed system time as past #5120

@juhwan-jeong

Description

@juhwan-jeong

I used throttleFirst operator for prevening duplicated click event like below

RxView.clicks(v).throttleFirst(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())

It works well in general case. But if user changed system time as past after click view, thrrottleFist doesn't emit item. (In the android, user can change system time using settings application.)
Because, OperatorThrottleFirst's below routine.

    @Override
    public Subscriber<? super T> call(final Subscriber<? super T> subscriber) {
        return new Subscriber<T>(subscriber) {

            private long lastOnNext = -1;
            // ...
            @Override
            public void onNext(T v) {
                long now = scheduler.now();
                if (lastOnNext == -1 || now - lastOnNext >= timeInMilliseconds) {
                    lastOnNext = now;
                    subscriber.onNext(v);
                }
            }

I think (now - lastOnNext) become negative value, item should be emitted too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions