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

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

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

Observable.fromCallable介绍

暂无

代码示例

代码示例来源:origin: alipay/sofa-rpc

@Override
protected Observable resumeWithFallback() {
  return Observable.fromCallable(new Callable<FallbackFactory>() {
    @Override
    public FallbackFactory call() throws Exception {

代码示例来源:origin: alipay/sofa-rpc

@Override
protected Observable resumeWithFallback() {
  return Observable.fromCallable(new Callable<FallbackFactory>() {
    @Override
    public FallbackFactory call() throws Exception {

代码示例来源:origin: hidroh/materialistic

public static void init(Context context, Scheduler scheduler) {
  Observable.fromCallable(() -> loadFromAssets(context))
      .onErrorReturn(throwable -> null)
      .subscribeOn(scheduler)
      .subscribe();
}

代码示例来源:origin: hidroh/materialistic

public void refreshStories(String filter, @ItemManager.CacheMode int cacheMode) {
  if (mItems == null || mItems.getValue() == null) {
    return;
  }
  Observable.fromCallable(() -> mItemManager.getStories(filter, cacheMode))
      .subscribeOn(mIoThreadScheduler)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(items -> setItems(items));
}

代码示例来源:origin: hidroh/materialistic

public LiveData<Pair<Item[], Item[]>> getStories(String filter, @ItemManager.CacheMode int cacheMode) {
  if (mItems == null) {
    mItems = new MutableLiveData<>();
    Observable.fromCallable(() -> mItemManager.getStories(filter, cacheMode))
        .subscribeOn(mIoThreadScheduler)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(items -> setItems(items));
  }
  return mItems;
}

代码示例来源:origin: pavlospt/RxFile

public static Observable<Bitmap> getVideoThumbnail(final String filePath) {
 return Observable.fromCallable(new Func0<Bitmap>() {
  @Override
  public Bitmap call() {
   return ThumbnailUtils.createVideoThumbnail(filePath,
     MediaStore.Images.Thumbnails.MINI_KIND);
  }
 });
}

代码示例来源:origin: com.couchbase.client/core-io

@Override
public Observable<Boolean> shutdown() {
  return Observable.fromCallable(new Callable<Boolean>() {
    @Override
    public Boolean call() {
      ((ThresholdLogTracer) tracer).shutdown();
      shutdown = true;
      return true;
    }
  });
}

代码示例来源:origin: com.couchbase.client/core-io

@Override
public Observable<Boolean> shutdown() {
  return Observable.fromCallable(new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
      orphanResponseReporter.shutdown();
      shutdown = true;
      return true;
    }
  });
}

代码示例来源:origin: pavlospt/RxFile

public static Observable<Bitmap> getThumbnailFromPath(String filePath) {
 final Bitmap sourceBitmap = BitmapFactory.decodeFile(filePath);
 return Observable.fromCallable(new Func0<Bitmap>() {
  @Override
  public Bitmap call() {
   return ThumbnailUtils.
     extractThumbnail(sourceBitmap, sourceBitmap.getWidth(), sourceBitmap.getHeight());
  }
 });
}

代码示例来源:origin: XiqingLiu/GEEK

public static void getObAnycodesPdf(Observer<List<AnyCodesPDF>> subscribe) {
  Observable.fromCallable(new Callable<List<AnyCodesPDF>>() {
    @Override
    public List<AnyCodesPDF> call() throws Exception {
      return Anycodes.getPDFResource("http://study.anycodes.cn/index.php?mod=folder&sid=18oOe3", 1);
    }
  }).subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(subscribe);
}

代码示例来源:origin: XiqingLiu/GEEK

public static void getObRxOperators(Observer<List<Operators>> subscribe) {
  Observable.fromCallable(new Callable<List<Operators>>() {
    @Override
    public List<Operators> call() throws Exception {
      return RxJavaDataUtils.getOperators();
    }
  }).subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(subscribe);
}

代码示例来源:origin: pavlospt/RxFile

public static Observable<String> getFileType(String filePath) {
 logDebug("Filepath in getFileType: " + filePath);
 final String[] parts = filePath.split("/");
 return Observable.fromCallable(new Func0<String>() {
  @Override
  public String call() {
   return parts.length > 0 ? URLConnection.guessContentTypeFromName(parts[0]) : null;
  }
 });
}

代码示例来源:origin: a-voyager/WeekToDo

public static Observable<Boolean> backup() {
  File src = new File(Constants.ExternalStorageDirectory + Constants.DATABASE_FILE_PATH_FOLDER, Constants.DATABASE_FILE_PATH_FILE_NAME);
  File desDir = new File(Constants.ExternalStorageDirectory + Constants.DATABASE_FILE_BACKUP_PATH_FOLDER);
  desDir.mkdirs();
  File des = new File(desDir, src.getName());
  return Observable
      .fromCallable(() -> FileUtils.copyFile(src, des))
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: a-voyager/WeekToDo

public static Observable<Boolean> recovery() {
  File des = new File(Constants.ExternalStorageDirectory + Constants.DATABASE_FILE_PATH_FOLDER, Constants.DATABASE_FILE_PATH_FILE_NAME);
  File src = new File(Constants.ExternalStorageDirectory + Constants.DATABASE_FILE_BACKUP_PATH_FOLDER, des.getName());
  return Observable
      .fromCallable(() -> FileUtils.copyFile(src, des))
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: Aptoide/aptoide-client-v8

public Observable<List<Notification>> getAllSorted(Sort sort) {
 return Observable.fromCallable(() -> database.get())
   .flatMap(realm -> realm.where(Notification.class)
     .findAllSorted("timeStamp", sort)
     .asObservable())
   .unsubscribeOn(RealmSchedulers.getScheduler())
   .flatMap((data) -> database.copyFromRealm(data))
   .subscribeOn(RealmSchedulers.getScheduler())
   .observeOn(Schedulers.io());
}

代码示例来源:origin: Aptoide/aptoide-client-v8

public Observable<List<Installed>> getAllInstalledSorted() {
 return Observable.fromCallable(() -> database.get())
   .flatMap(realm -> realm.where(Installed.class)
     .findAllSorted(Installed.NAME, Sort.ASCENDING)
     .asObservable()
     .unsubscribeOn(RealmSchedulers.getScheduler()))
   .filter(installed -> installed.isValid())
   .flatMap(installed -> database.copyFromRealm(installed))
   .subscribeOn(RealmSchedulers.getScheduler())
   .observeOn(Schedulers.io())
   .flatMap(installs -> filterCompleted(installs));
}

代码示例来源:origin: kennyk65/Microservices-With-Spring-Student-Files

@Override
@HystrixCommand(fallbackMethod="getFallbackSubject")
public Observable<Word> getSubject() {
  //	This 'reactive' observable is backed by a regular Java Callable, which can run in a different thread:
  return Observable.fromCallable(
    () ->  new Word (subjectClient.getWord().getWord(), Role.subject)
  ).subscribeOn(Schedulers.from(executor));
}

代码示例来源:origin: kennyk65/Microservices-With-Spring-Student-Files

@Override
@HystrixCommand(fallbackMethod="getFallbackArticle")
public Observable<Word> getArticle() {
  return Observable.fromCallable(
    () ->  new Word (articleClient.getWord().getWord(), Role.article)
  ).subscribeOn(Schedulers.from(executor));
}

代码示例来源:origin: Aptoide/aptoide-client-v8

public Observable<List<Installed>> getAsList(String packageName, int versionCode) {
 return Observable.fromCallable(() -> database.get())
   .flatMap(realm -> realm.where(Installed.class)
     .equalTo(Installed.PACKAGE_NAME, packageName)
     .equalTo(Installed.VERSION_CODE, versionCode)
     .findAll()
     .asObservable()
     .unsubscribeOn(RealmSchedulers.getScheduler()))
   .flatMap(installeds -> database.copyFromRealm(installeds))
   .subscribeOn(RealmSchedulers.getScheduler());
}

代码示例来源:origin: nurkiewicz/rxjava-book-examples

@Test
public void sample_107() throws Exception {
  Observable<Integer> obs = Observable
      .just(3, 0, 2, 0, 1, 0)
      .concatMapDelayError(x -> Observable.fromCallable(() -> 100 / x));
  TestSubscriber<Integer> ts = new TestSubscriber<>();
  obs.subscribe(ts);
  ts.assertValues(33, 50, 100);
  ts.assertError(ArithmeticException.class);  //Fails (!)
}

相关文章

Observable类方法