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

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

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

Observable.just介绍

[英]Returns an Observable that emits a single item and then completes.

To convert any object into an Observable that emits that object, pass that object into the justmethod.

This is similar to the #from(java.lang.Object[]) method, except that from will convert an Iterable object into an Observable that emits each of the items in the Iterable, one at a time, while the just method converts an Iterable into an Observable that emits the entire Iterable as a single item. Scheduler: just does not operate by default on a particular Scheduler.
[中]返回一个可观察对象,该对象发出单个项,然后完成。
要将任何对象转换为发射该对象的可观察对象,请将该对象传递给justmethod。
这与#from(java.lang.Object[])方法类似,不同之处在于from将把一个Iterable对象转换成一个Observable对象,一次一个地发射Iterable中的每个项,而just方法将Iterable转换成一个Observable对象,作为单个项发射整个Iterable。调度器:只是默认情况下不会在特定的调度器上运行。

代码示例

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

@Override
  public Observable<T> call() {
    T result;
    try {
      result = callable.call();
    } catch (Exception e) {
      return Observable.error(e);
    }
    return Observable.just(result);
  }
});

代码示例来源: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: davidmoten/rxjava-jdbc

/**
 * Sets a named parameter. If name is null throws a
 * {@link NullPointerException}. If value is instance of Observable then
 * throws an {@link IllegalArgumentException}.
 * 
 * @param name
 *            the parameter name. Cannot be null.
 * @param value
 *            the parameter value
 */
void parameter(String name, Object value) {
  Preconditions.checkNotNull(name, "parameter name cannot be null");
  if (value instanceof Observable)
    throw new IllegalArgumentException(
        "use parameters() method not the parameter() method for an Observable");
  this.parameters = parameters.concatWith(Observable.just(new Parameter(name, value)));
}

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<PolicySetDefinitionInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl<PolicySetDefinitionInner>> result = listBuiltInDelegate(response);
      return Observable.just(new ServiceResponse<Page<PolicySetDefinitionInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<SubscriptionInner>>> call(ServiceResponse<Page<SubscriptionInner>> page) {
    String nextPageLink = page.body().nextPageLink();
    if (nextPageLink == null) {
      return Observable.just(page);
    }
    return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink));
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<ProviderInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl<ProviderInner>> result = listNextDelegate(response);
      return Observable.just(new ServiceResponse<Page<ProviderInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<PolicySetDefinitionInner>>> call(ServiceResponse<Page<PolicySetDefinitionInner>> page) {
    String nextPageLink = page.body().nextPageLink();
    if (nextPageLink == null) {
      return Observable.just(page);
    }
    return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink));
  }
});

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

@Override
  public Observable<R> call() {
    try {
      return Observable.just(getFallback());
    } catch (Throwable ex) {
      return Observable.error(ex);
    }
  }
});

代码示例来源: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: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<TenantIdDescriptionInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl1<TenantIdDescriptionInner>> result = listNextDelegate(response);
      return Observable.just(new ServiceResponse<Page<TenantIdDescriptionInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<PolicySetDefinitionInner>>> call(ServiceResponse<Page<PolicySetDefinitionInner>> page) {
    String nextPageLink = page.body().nextPageLink();
    if (nextPageLink == null) {
      return Observable.just(page);
    }
    return Observable.just(page).concatWith(listBuiltInNextWithServiceResponseAsync(nextPageLink));
  }
});

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

private Observable<Response> execute(Request request) {
  return Observable.defer(() -> {
    try {
      return Observable.just(mCallFactory.newCall(request).execute());
    } catch (IOException e) {
      return Observable.error(e);
    }
  }).subscribeOn(mIoScheduler);
}

代码示例来源:origin: jhusain/learnrxjava

Observable.just("Hello", "World!")
    .subscribe(System.out::println);
Observable.just("Hello World!")
    .subscribe(System.out::println,
        Throwable::printStackTrace,
    .onErrorResumeNext(e -> Observable.just("Fallback Data"))
    .subscribe(System.out::println);
  throw new RuntimeException("failed!");
}).onErrorResumeNext(throwable -> {
  return Observable.just("fallback value");
}).subscribe(System.out::println);
}).onErrorResumeNext(Observable.just("fallback value"))
    .subscribe(System.out::println);
        System.out.println("delay retry by " + i + " second(s)");
        return Observable.timer(i, TimeUnit.SECONDS);
      }).concatWith(Observable.error(new RuntimeException("Exceeded 3 retries")));
})
    .subscribe(System.out::println, t -> t.printStackTrace());

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<FeatureResultInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl<FeatureResultInner>> result = list1Delegate(response);
      return Observable.just(new ServiceResponse<Page<FeatureResultInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<ProviderInner>>> call(ServiceResponse<Page<ProviderInner>> page) {
    String nextPageLink = page.body().nextPageLink();
    if (nextPageLink == null) {
      return Observable.just(page);
    }
    return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink));
  }
});

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

@Override
public void login(String username, String password, boolean createAccount, Callback callback) {
  execute(postLogin(username, password, createAccount))
      .flatMap(response -> {
        if (response.code() == HttpURLConnection.HTTP_OK) {
          return Observable.error(new UserServices.Exception(parseLoginError(response)));
        }
        return Observable.just(response.code() == HttpURLConnection.HTTP_MOVED_TEMP);
      })
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(callback::onDone, callback::onError);
}

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<TagDetailsInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl<TagDetailsInner>> result = listNextDelegate(response);
      return Observable.just(new ServiceResponse<Page<TagDetailsInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<PolicyDefinitionInner>>> call(ServiceResponse<Page<PolicyDefinitionInner>> page) {
    String nextPageLink = page.body().nextPageLink();
    if (nextPageLink == null) {
      return Observable.just(page);
    }
    return Observable.just(page).concatWith(listByManagementGroupNextWithServiceResponseAsync(nextPageLink));
  }
});

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

@Override
  protected Observable<Boolean> resumeWithFallback() {
    if (fallbackBehavior == FALLBACK_SUCCESS) {
      return Observable.just(false);
    } else if (fallbackBehavior == FALLBACK_FAILURE) {
      RuntimeException ex = new RuntimeException("fallback failure");
      if (asyncFallbackException) {
        return Observable.error(ex);
      } else {
        throw ex;
      }
    } else { //FALLBACK_NOT_IMPLEMENTED
      return super.resumeWithFallback();
    }
  }
}

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

@Override
  public Observable<ServiceResponse<Page<DeploymentOperationInner>>> call(Response<ResponseBody> response) {
    try {
      ServiceResponse<PageImpl<DeploymentOperationInner>> result = listByResourceGroupDelegate(response);
      return Observable.just(new ServiceResponse<Page<DeploymentOperationInner>>(result.body(), result.response()));
    } catch (Throwable t) {
      return Observable.error(t);
    }
  }
});

相关文章

Observable类方法