本文整理汇总了Java中rx.Scheduler.Worker.schedule方法的典型用法代码示例。如果您正苦于以下问题:Java Worker.schedule方法的具体用法?Java Worker.schedule怎么用?Java Worker.schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.Scheduler.Worker
的用法示例。
在下文中一共展示了Worker.schedule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWorkOnNewTrampoline
import rx.Scheduler.Worker; //导入方法依赖的package包/类
private static Worker doWorkOnNewTrampoline(final String key, final ArrayList<String> workDone) {
Worker worker = Schedulers.trampoline().createWorker();
worker.schedule(new Action0() {
@Override
public void call() {
String msg = key + ".1";
workDone.add(msg);
System.out.println(msg);
Worker worker3 = Schedulers.trampoline().createWorker();
worker3.schedule(createPrintAction(key + ".B.1", workDone));
worker3.schedule(createPrintAction(key + ".B.2", workDone));
}
});
return worker;
}
示例2: blockUntilWorkFinished
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public static void blockUntilWorkFinished(Scheduler scheduler, int numThreads, long timeout,
TimeUnit unit) {
final CountDownLatch latch = new CountDownLatch(numThreads);
for (int i = 1; i <= numThreads; i++) {
final Worker worker = scheduler.createWorker();
worker.schedule(new Action0() {
@Override
public void call() {
worker.unsubscribe();
latch.countDown();
}
});
}
try {
boolean finished = latch.await(timeout, unit);
if (!finished) {
throw new RuntimeException("timeout occured waiting for work to finish");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
示例3: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Override
public Subscriber<? super T> call(Subscriber<? super T> child) {
Subscriber<T> parent;
if (firstTime.compareAndSet(true, false)) {
// don't delay subscription for the first time
parent = Subscribers.from(child);
} else {
final PublishSubject<T> subject = PublishSubject.create();
Worker worker = scheduler.createWorker();
worker.schedule(() -> {
subject.unsafeSubscribe(child);
}, duration, units);
child.add(worker);
parent = Subscribers.from(subject);
}
child.add(parent);
return parent;
}
示例4: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super Long> child) {
Worker worker = scheduler.createWorker();
child.add(worker);
worker.schedule(new Action0() {
@Override
public void call() {
try {
child.onNext(0L);
} catch (Throwable t) {
child.onError(t);
return;
}
child.onCompleted();
}
}, time, unit);
}
示例5: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public Subscriber<? super T> call(final Subscriber<? super T> child) {
Worker worker = this.scheduler.createWorker();
child.add(worker);
final AtomicBoolean gate = new AtomicBoolean();
worker.schedule(new Action0() {
public void call() {
gate.set(true);
}
}, this.time, this.unit);
return new Subscriber<T>(child) {
public void onNext(T t) {
if (gate.get()) {
child.onNext(t);
}
}
public void onError(Throwable e) {
try {
child.onError(e);
} finally {
unsubscribe();
}
}
public void onCompleted() {
try {
child.onCompleted();
} finally {
unsubscribe();
}
}
};
}
示例6: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public void call(final Subscriber<? super T> s) {
Worker worker = this.scheduler.createWorker();
s.add(worker);
worker.schedule(new Action0() {
public void call() {
if (!s.isUnsubscribed()) {
OnSubscribeDelaySubscription.this.source.unsafeSubscribe(Subscribers.wrap(s));
}
}
}, this.time, this.unit);
}
示例7: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public void call(final Subscriber<? super Long> child) {
Worker worker = this.scheduler.createWorker();
child.add(worker);
worker.schedule(new Action0() {
public void call() {
try {
child.onNext(Long.valueOf(0));
child.onCompleted();
} catch (Throwable t) {
Exceptions.throwOrReport(t, child);
}
}
}, this.time, this.unit);
}
示例8: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super T> child) {
Worker worker = this.scheduler.createWorker();
child.add(worker);
TakeSubscriber<T> ts = new TakeSubscriber(new SerializedSubscriber(child));
worker.schedule(ts, this.time, this.unit);
return ts;
}
示例9: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public Subscription call(final TimeoutSubscriber<T> timeoutSubscriber, final Long seqId, Worker inner) {
return inner.schedule(new Action0() {
public void call() {
timeoutSubscriber.onTimeout(seqId.longValue());
}
}, this.val$timeout, this.val$timeUnit);
}
示例10: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
public Subscriber<? super T> call(final Subscriber<? super T> child) {
final Worker worker = this.scheduler.createWorker();
child.add(worker);
return new Subscriber<T>(child) {
boolean done;
public void onCompleted() {
worker.schedule(new Action0() {
public void call() {
if (!AnonymousClass1.this.done) {
AnonymousClass1.this.done = true;
child.onCompleted();
}
}
}, OperatorDelay.this.delay, OperatorDelay.this.unit);
}
public void onError(final Throwable e) {
worker.schedule(new Action0() {
public void call() {
if (!AnonymousClass1.this.done) {
AnonymousClass1.this.done = true;
child.onError(e);
worker.unsubscribe();
}
}
});
}
public void onNext(final T t) {
worker.schedule(new Action0() {
public void call() {
if (!AnonymousClass1.this.done) {
child.onNext(t);
}
}
}, OperatorDelay.this.delay, OperatorDelay.this.unit);
}
};
}
示例11: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super T> subscriber) {
if (!subscriber.isUnsubscribed()) {
try {
final ProxyProducer<T> producer = getProducer(subscriber, mCachedValue.get());
final Worker worker = mScheduler.createWorker();
subscriber.add(worker);
subscriber.setProducer(producer);
final Callback<T> listener = new Callback<T>() {
@Override
public void notify(final T value) {
if (!subscriber.isUnsubscribed()) {
worker.schedule(new Action0() {
@Override
public void call() {
producer.offer(value);
}
});
}
}
};
addCallback(listener);
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
removeCallback(listener);
}
}));
} catch (RuntimeException e) {
subscriber.onError(e);
}
}
}
示例12: racy
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Test
public void racy() throws Exception {
Worker worker = Schedulers.computation().createWorker();
try {
for (int i = 0; i < 1000; i++) {
AtomicInteger wip = new AtomicInteger(2);
PublishSubject<Integer> ps = PublishSubject.create();
AssertableSubscriber<Integer> as = ps.test(1);
CountDownLatch cdl = new CountDownLatch(1);
worker.schedule(() -> {
if (wip.decrementAndGet() != 0) {
while (wip.get() != 0) ;
}
ps.onNext(1);
cdl.countDown();
});
if (wip.decrementAndGet() != 0) {
while (wip.get() != 0) ;
}
ps.onNext(1);
cdl.await();
as.assertFailure(MissingBackpressureException.class, 1);
}
} finally {
worker.unsubscribe();
}
}
示例13: nonRacy
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Test
public void nonRacy() throws Exception {
Worker worker = Schedulers.computation().createWorker();
try {
for (int i = 0; i < 1000; i++) {
AtomicInteger wip = new AtomicInteger(2);
Subject<Integer, Integer> ps = PublishSubject.<Integer>create().toSerialized();
AssertableSubscriber<Integer> as = ps.test(1);
CountDownLatch cdl = new CountDownLatch(1);
worker.schedule(() -> {
if (wip.decrementAndGet() != 0) {
while (wip.get() != 0) ;
}
ps.onNext(1);
cdl.countDown();
});
if (wip.decrementAndGet() != 0) {
while (wip.get() != 0) ;
}
ps.onNext(1);
cdl.await();
as.assertFailure(MissingBackpressureException.class, 1);
}
} finally {
worker.unsubscribe();
}
}
示例14: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) {
final Worker worker = scheduler.createWorker();
child.add(worker);
final AtomicBoolean gate = new AtomicBoolean();
worker.schedule(new Action0() {
@Override
public void call() {
gate.set(true);
}
}, time, unit);
return new Subscriber<T>(child) {
@Override
public void onNext(T t) {
if (gate.get()) {
child.onNext(t);
}
}
@Override
public void onError(Throwable e) {
try {
child.onError(e);
} finally {
unsubscribe();
}
}
@Override
public void onComplete() {
try {
child.onComplete();
} finally {
unsubscribe();
}
}
};
}
示例15: call
import rx.Scheduler.Worker; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super T> s) {
final Worker worker = scheduler.createWorker();
s.add(worker);
worker.schedule(new Action0() {
@Override
public void call() {
if (!s.isUnsubscribed()) {
source.unsafeSubscribe(s);
}
}
}, time, unit);
}