rx.Observable.subscribeOn()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中rx.Observable.subscribeOn()方法的一些代码示例,展示了Observable.subscribeOn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.subscribeOn()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:subscribeOn

Observable.subscribeOn介绍

[英]Asynchronously subscribes Observers to this Observable on the specified Scheduler.

Scheduler: you specify which Scheduler this operator will use
[中]在指定的调度程序上异步订阅此可观察对象的观察者。
调度器:指定该操作员将使用的调度器

代码示例

代码示例来源:origin: greenrobot/greenDAO

protected <R> Observable<R> wrap(Observable<R> observable) {
  if (scheduler != null) {
    return observable.subscribeOn(scheduler);
  } else {
    return observable;
  }
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onError(new RuntimeException("graceful onError"));
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      s.onError(new RuntimeException("onError"));
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      s.onError(new RuntimeException("onError"));
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      throw new RuntimeException("bad onError");
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> resumeWithFallback() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onNext(false);
      s.onCompleted();
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> resumeWithFallback() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onNext(false);
      s.onCompleted();
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onNext(true);
      s.onCompleted();
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> resumeWithFallback() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onNext(false);
      s.onCompleted();
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> resumeWithFallback() {
  return Observable.create(new OnSubscribe<Boolean>() {
    @Override
    public void call(Subscriber<? super Boolean> s) {
      results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
      results.originThread.set(Thread.currentThread());
      s.onNext(false);
      s.onCompleted();
    }
  }).subscribeOn(userScheduler);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  System.out.println("successfully executed");
  return Observable.just(true).subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
  protected Observable<Boolean> resumeWithFallback() {
    return Observable.just(false).subscribeOn(Schedulers.computation());
  }
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<T> construct() {
  executed = true;
  System.out.println("successfully executed");
  return Observable.just(value).subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  System.out.println("successfully executed");
  return Observable.just(true).subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<String> construct() {
  executed = true;
  System.out.println("successfully executed");
  return Observable.just(value).subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  System.out.println("successfully executed");
  return Observable.just(true).subscribeOn(Schedulers.computation());
}

代码示例来源:origin: square/retrofit

@Override public Object adapt(Call<R> call) {
  OnSubscribe<Response<R>> callFunc = isAsync
    ? new CallEnqueueOnSubscribe<>(call)
    : new CallExecuteOnSubscribe<>(call);

  OnSubscribe<?> func;
  if (isResult) {
   func = new ResultOnSubscribe<>(callFunc);
  } else if (isBody) {
   func = new BodyOnSubscribe<>(callFunc);
  } else {
   func = callFunc;
  }
  Observable<?> observable = Observable.create(func);

  if (scheduler != null) {
   observable = observable.subscribeOn(scheduler);
  }

  if (isSingle) {
   return observable.toSingle();
  }
  if (isCompletable) {
   return observable.toCompletable();
  }
  return observable;
 }
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Integer> construct() {
  return Observable.just(1, 2, 3)
      .concatWith(Observable.<Integer> error(new RuntimeException("forced error")))
      .subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<Boolean> construct() {
  return Observable.just(false, true, false)
      .concatWith(Observable.<Boolean>error(new RuntimeException("forced error")))
      .subscribeOn(Schedulers.computation());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<String> construct() {
  executed = true;
  return Observable.just(value).delay(duration, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation())
      .doOnNext(new Action1<String>() {
        @Override
        public void call(String t1) {
          System.out.println("successfully executed");
        }
      });
}

相关文章

Observable类方法