Change the license to GPL v3 to be compatible with Apache License 2.0.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package rx.subscriptions;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
|
||||
/**
|
||||
* Subscription that can be checked for status such as in a loop inside an {@link Observable} to exit the loop if unsubscribed.
|
||||
*
|
||||
* @see Rx.Net equivalent BooleanDisposable at http://msdn.microsoft.com/en-us/library/system.reactive.disposables.booleandisposable(v=vs.103).aspx
|
||||
*/
|
||||
public class BooleanSubscription implements Subscription {
|
||||
|
||||
private final AtomicBoolean unsubscribed = new AtomicBoolean(false);
|
||||
|
||||
public boolean isUnsubscribed() {
|
||||
return unsubscribed.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
unsubscribed.set(true);
|
||||
}
|
||||
|
||||
}
|
||||
58
HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java
Normal file
58
HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package rx.subscriptions;
|
||||
|
||||
import rx.Subscription;
|
||||
import rx.util.functions.Action0;
|
||||
import rx.util.functions.FuncN;
|
||||
import rx.util.functions.Functions;
|
||||
|
||||
public class Subscriptions {
|
||||
/**
|
||||
* A {@link Subscription} that does nothing.
|
||||
*
|
||||
* @return {@link Subscription}
|
||||
*/
|
||||
public static Subscription empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Subscription} implemented via a Func
|
||||
*
|
||||
* @return {@link Subscription}
|
||||
*/
|
||||
public static Subscription create(final Action0 unsubscribe) {
|
||||
return new Subscription() {
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
unsubscribe.call();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Subscription} implemented via an anonymous function (such as closures from other languages).
|
||||
*
|
||||
* @return {@link Subscription}
|
||||
*/
|
||||
public static Subscription create(final Object unsubscribe) {
|
||||
final FuncN<?> f = Functions.from(unsubscribe);
|
||||
return new Subscription() {
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
f.call();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Subscription} that does nothing when its unsubscribe method is called.
|
||||
*/
|
||||
private static Subscription EMPTY = new Subscription() {
|
||||
public void unsubscribe() {
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user