| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.operators.flowable; |
| 15 |
|
| 16 |
import org.reactivestreams.*; |
| 17 |
|
| 18 |
import io.reactivex.rxjava3.annotations.Nullable; |
| 19 |
import io.reactivex.rxjava3.core.*; |
| 20 |
import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper; |
| 21 |
import io.reactivex.rxjava3.operators.QueueSubscription; |
| 22 |
|
| 23 |
public final class FlowableIgnoreElements<T> extends AbstractFlowableWithUpstream<T, T> { |
| 24 |
|
| 25 |
public FlowableIgnoreElements(Flowable<T> source) { |
| 26 |
super(source); |
| 27 |
} |
| 28 |
|
| 29 |
@Override |
| 30 |
protected void subscribeActual(final Subscriber<? super T> t) { |
| 31 |
source.subscribe(new IgnoreElementsSubscriber<>(t)); |
| 32 |
} |
| 33 |
|
| 34 |
static final class IgnoreElementsSubscriber<T> implements FlowableSubscriber<T>, QueueSubscription<T> { |
| 35 |
final Subscriber<? super T> downstream; |
| 36 |
|
| 37 |
Subscription upstream; |
| 38 |
|
| 39 |
IgnoreElementsSubscriber(Subscriber<? super T> downstream) { |
| 40 |
this.downstream = downstream; |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void onSubscribe(Subscription s) { |
| 45 |
if (SubscriptionHelper.validate(this.upstream, s)) { |
| 46 |
this.upstream = s; |
| 47 |
downstream.onSubscribe(this); |
| 48 |
s.request(Long.MAX_VALUE); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public void onNext(T t) { |
| 54 |
// deliberately ignored |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public void onError(Throwable t) { |
| 59 |
downstream.onError(t); |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public void onComplete() { |
| 64 |
downstream.onComplete(); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public boolean offer(T e) { |
| 69 |
throw new UnsupportedOperationException("Should not be called!"); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public boolean offer(T v1, T v2) { |
| 74 |
throw new UnsupportedOperationException("Should not be called!"); |
| 75 |
} |
| 76 |
|
| 77 |
@Nullable |
| 78 |
@Override |
| 79 |
public T poll() { |
| 80 |
return null; // empty, always |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public boolean isEmpty() { |
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
public void clear() { |
| 90 |
// always empty |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public void request(long n) { |
| 95 |
// never emits a value |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public void cancel() { |
| 100 |
upstream.cancel(); |
| 101 |
} |
| 102 |
|
| 103 |
@Override |
| 104 |
public int requestFusion(int mode) { |
| 105 |
return mode & ASYNC; |
| 106 |
} |
| 107 |
} |
| 108 |
} |