本文整理汇总了Java中rx.subscriptions.Subscriptions.create方法的典型用法代码示例。如果您正苦于以下问题:Java Subscriptions.create方法的具体用法?Java Subscriptions.create怎么用?Java Subscriptions.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.subscriptions.Subscriptions
的用法示例。
在下文中一共展示了Subscriptions.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enqueue
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private Subscription enqueue(Action0 action, long execTime) {
if (this.innerSubscription.isUnsubscribed()) {
return Subscriptions.unsubscribed();
}
final TimedAction timedAction = new TimedAction(action, Long.valueOf(execTime), this.counter.incrementAndGet());
this.queue.add(timedAction);
if (this.wip.getAndIncrement() != 0) {
return Subscriptions.create(new Action0() {
public void call() {
InnerCurrentThreadScheduler.this.queue.remove(timedAction);
}
});
}
do {
TimedAction polled = (TimedAction) this.queue.poll();
if (polled != null) {
polled.action.call();
}
} while (this.wip.decrementAndGet() > 0);
return Subscriptions.unsubscribed();
}
示例2: disconnect
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private Subscription disconnect(final CompositeSubscription current) {
return Subscriptions.create(new Action0() {
public void call() {
OnSubscribeRefCount.this.lock.lock();
try {
if (OnSubscribeRefCount.this.baseSubscription == current && OnSubscribeRefCount.this.subscriptionCount.decrementAndGet() == 0) {
OnSubscribeRefCount.this.baseSubscription.unsubscribe();
OnSubscribeRefCount.this.baseSubscription = new CompositeSubscription();
}
OnSubscribeRefCount.this.lock.unlock();
} catch (Throwable th) {
OnSubscribeRefCount.this.lock.unlock();
}
}
});
}
示例3: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Intent> subscriber)
{
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
subscriber.onNext(intent);
}
};
final Subscription subscription = Subscriptions.create(new Action0()
{
@Override
public void call()
{
mContext.unregisterReceiver(broadcastReceiver);
}
});
subscriber.add(subscription);
mContext.registerReceiver(broadcastReceiver, mIntentFilter, mBroadcastPermission, mSchedulerHandler);
}
示例4: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Intent> subscriber)
{
final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(mContext);
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
subscriber.onNext(intent);
}
};
final Subscription subscription = Subscriptions.create(new Action0()
{
@Override
public void call()
{
localBroadcastManager.unregisterReceiver(broadcastReceiver);
}
});
subscriber.add(subscription);
localBroadcastManager.registerReceiver(broadcastReceiver, mIntentFilter);
}
示例5: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Intent> subscriber) {
final BroadcastReceiver broadCastReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
subscriber.onNext(intent);
}
};
final Subscription subscription= Subscriptions.create(new Action0() {
@Override
public void call() {
context.unregisterReceiver(broadCastReceiver);
}
});
subscriber.add(subscription);
context.registerReceiver(broadCastReceiver, intentFilter, permission, schedulerHandler);
}
示例6: unsubscribeInUiThread
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private Subscription unsubscribeInUiThread(final Action0 unsubscribe) {
return Subscriptions.create(new Action0() {
@Override public void call() {
if (Looper.getMainLooper() == Looper.myLooper()) {
unsubscribe.call();
} else {
final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
inner.schedule(new Action0() {
@Override public void call() {
unsubscribe.call();
inner.unsubscribe();
}
});
}
}
});
}
示例7: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override public void call(final Subscriber<? super Intent> subscriber) {
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(intent);
}
}
};
final Subscription subscription = Subscriptions.create(new Action0() {
@Override public void call() {
context.unregisterReceiver(broadcastReceiver);
}
});
subscriber.add(subscription);
context.registerReceiver(broadcastReceiver, intentFilter, broadcastPermission,
schedulerHandler);
}
示例8: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Intent> subscriber) {
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
subscriber.onNext(intent);
}
};
final Subscription subscription = Subscriptions.create(new Action0() {
@Override
public void call() {
context.unregisterReceiver(receiver);
}
});
subscriber.add(subscription);
context.registerReceiver(receiver, intent);
}
示例9: unsubscribeInUiThread
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private Subscription unsubscribeInUiThread(final Action0 unsubscribe) {
return Subscriptions.create(new Action0() {
@Override
public void call() {
if (Looper.getMainLooper() == Looper.myLooper()) {
unsubscribe.call();
} else {
final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
inner.schedule(new Action0() {
@Override
public void call() {
unsubscribe.call();
inner.unsubscribe();
}
});
}
}
});
}
示例10: call
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Intent> subscriber) {
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
subscriber.onNext(intent);
}
};
final Subscription subscription = Subscriptions.create(new Action0() {
@Override
public void call() {
context.unregisterReceiver(broadcastReceiver);
}
});
subscriber.add(subscription);
context.registerReceiver(broadcastReceiver, intentFilter, broadcastPermission, schedulerHandler);
}
示例11: unsubscribeInUiThread
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private static Subscription unsubscribeInUiThread(final Action0 unsubscribe) {
return Subscriptions.create(new Action0() {
@Override public void call() {
if (Looper.getMainLooper() == Looper.myLooper()) {
unsubscribe.call();
} else {
final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
inner.schedule(new Action0() {
@Override public void call() {
unsubscribe.call();
inner.unsubscribe();
}
});
}
}
});
}
示例12: performTestUsingWithObservableFactoryError
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
private void performTestUsingWithObservableFactoryError(boolean disposeEagerly) {
final Action0 unsubscribe = mock(Action0.class);
Supplier<Subscription> resourceFactory = new Supplier<Subscription>() {
@Override
public Subscription call() {
return Subscriptions.create(unsubscribe);
}
};
Function<Subscription, Observable<Integer>> observableFactory = new Function<Subscription, Observable<Integer>>() {
@Override
public Observable<Integer> call(Subscription subscription) {
throw new TestException();
}
};
try {
Observable.using(resourceFactory, observableFactory, disposeSubscription).toBlocking()
.last();
fail("Should throw a TestException when the observableFactory throws it");
} catch (TestException e) {
// Make sure that unsubscribe is called so that users can close
// the resource if some error happens.
verify(unsubscribe, times(1)).call();
}
}
示例13: unsubscribeOnMainThread
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
public static Subscription unsubscribeOnMainThread(final Action0 unsubscribe) {
return Subscriptions.create(new Action0() {
@Override
public void call() {
if (Looper.getMainLooper() == Looper.myLooper()) {
unsubscribe.call();
} else {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
unsubscribe.call();
}
});
}
}
});
}
示例14: schedule
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public <T> Subscription schedule(T state, final Func2<? super Scheduler, ? super T, ? extends Subscription> action, final CronExpression cronExpression, final Calendar calendar)
{
final AtomicBoolean complete = new AtomicBoolean();
Date initialfireTime = findNextExecutionTime(new Date(now()), cronExpression, calendar);
RecursiveAction<T> recursiveAction = new RecursiveAction<T>(complete, action, cronExpression, calendar, initialfireTime);
final Subscription sub;
if (initialfireTime == null)
{
sub = Subscriptions.empty();
}
else
{
sub = schedule(state, recursiveAction, initialfireTime);
}
return Subscriptions.create(new Action0()
{
@Override
public void call()
{
complete.set(true);
sub.unsubscribe();
}
});
}
示例15: onSubscribe
import rx.subscriptions.Subscriptions; //导入方法依赖的package包/类
@Override
public Subscription onSubscribe(final Observer<? super Long> observer)
{
final Subscription wrapped = scheduler.schedule(new Action0()
{
@Override
public void call()
{
observer.onNext(currentValue);
currentValue++;
}
}, cronExpression, calendar);
return Subscriptions.create(new Action0()
{
@Override
public void call()
{
wrapped.unsubscribe();
}
});
}