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

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

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

Observable.fromEmitter介绍

暂无

代码示例

代码示例来源:origin: evant/redux

public static <S> Observable<S> observable(final SimpleStore<S> store) {
  return Observable.fromEmitter(new Action1<Emitter<S>>() {
    @Override
    public void call(Emitter<S> emitter) {
      store.addListener(new EmitterListener<>(emitter, store));
    }
  }, Emitter.BackpressureMode.LATEST);
}

代码示例来源:origin: ArturVasilov/AndroidSchool

@NonNull
public Observable<String> observeChanges() {
  return Observable.fromEmitter(new Action1<AsyncEmitter<String>>() {
    @Override
    public void call(AsyncEmitter<String> asyncEmitter) {
      mEmitter = asyncEmitter;
      asyncEmitter.onNext(getText().toString());
    }
  }, AsyncEmitter.BackpressureMode.LATEST);
}

代码示例来源:origin: alessandrojp/android-easy-checkout

/**
 * Get the information about inventory of purchases made by a user from your app
 * This method will get all the purchases even if there are more than 500
 * This will be executed from Work Thread
 * See http://developer.android.com/google/play/billing/billing_integrate.html#QueryPurchases
 *
 * @param purchaseType IN_APP or SUBSCRIPTION
 */
public Observable<Purchases> getPurchases(final PurchaseType purchaseType) {
  return Observable.fromEmitter(new Action1<Emitter<Purchases>>() {
    @Override
    public void call(final Emitter<Purchases> emitter) {
      getBillingProcessor().getPurchases(purchaseType, new PurchasesHandler() {
        @Override
        public void onSuccess(Purchases purchases) {
          emitter.onNext(purchases);
          emitter.onCompleted();
        }
        @Override
        public void onError(BillingException e) {
          emitter.onError(e);
        }
      });
    }
  }, Emitter.BackpressureMode.LATEST);
}

代码示例来源:origin: alessandrojp/android-easy-checkout

/**
 * Get item details (SKU)
 * This will be executed from Work Thread
 * See http://developer.android.com/google/play/billing/billing_integrate.html#QueryDetails
 *
 * @param purchaseType IN_APP or SUBSCRIPTION
 * @param itemIds      list of SKU ids to be loaded
 */
public Observable<ItemDetails> getItemDetails(final PurchaseType purchaseType, final ArrayList<String> itemIds) {
  return Observable.fromEmitter(new Action1<Emitter<ItemDetails>>() {
    @Override
    public void call(final Emitter<ItemDetails> emitter) {
      getBillingProcessor().getItemDetails(purchaseType, itemIds, new ItemDetailsHandler() {
        @Override
        public void onSuccess(ItemDetails itemDetails) {
          emitter.onNext(itemDetails);
          emitter.onCompleted();
        }
        @Override
        public void onError(BillingException e) {
          emitter.onError(e);
        }
      });
    }
  }, Emitter.BackpressureMode.LATEST);
}

代码示例来源:origin: alessandrojp/android-easy-checkout

/**
 * Method deprecated, please use @{link {@link BillingProcessorObservable#getPurchases(PurchaseType)}}
 * <p>
 * Get the information about inventory of purchases made by a user from your app
 * This method will get all the purchases even if there are more than 500
 * This will be executed from Work Thread
 * See http://developer.android.com/google/play/billing/billing_integrate.html#QueryPurchases
 *
 * @param purchaseType IN_APP or SUBSCRIPTION
 */
@Deprecated
public Observable<Purchases> getInventory(final PurchaseType purchaseType) {
  return Observable.fromEmitter(new Action1<Emitter<Purchases>>() {
    @Override
    public void call(final Emitter<Purchases> emitter) {
      getBillingProcessor().getInventory(purchaseType, new InventoryHandler() {
        @Override
        public void onSuccess(Purchases purchases) {
          emitter.onNext(purchases);
          emitter.onCompleted();
        }
        @Override
        public void onError(BillingException e) {
          emitter.onError(e);
        }
      });
    }
  }, Emitter.BackpressureMode.LATEST);
}

代码示例来源:origin: ArturVasilov/AndroidSchool

@NonNull
@Override
public Observable<Boolean> addToFavourite(@NonNull Movie movie) {
  return Observable.fromEmitter(new Action1<AsyncEmitter<Boolean>>() {
    @Override
    public void call(AsyncEmitter<Boolean> emitter) {
      MoviesProvider.save(movie, MoviesProvider.Type.FAVOURITE);
      emitter.onNext(true);
      emitter.onCompleted();
    }
  }, AsyncEmitter.BackpressureMode.LATEST)
      .compose(RxUtils.async());
}

代码示例来源:origin: ArturVasilov/AndroidSchool

@NonNull
@Override
public Observable<Boolean> removeFromFavourite(@NonNull Movie movie) {
  return Observable.fromEmitter(new Action1<AsyncEmitter<Boolean>>() {
    @Override
    public void call(AsyncEmitter<Boolean> emitter) {
      MoviesProvider.delete(movie);
      emitter.onNext(false);
      emitter.onCompleted();
    }
  }, AsyncEmitter.BackpressureMode.LATEST)
      .compose(RxUtils.async());
}

代码示例来源:origin: TangoAgency/android-data-binding-rxjava

public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> observableField) {
    return Observable.fromEmitter(asyncEmitter -> {

      final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(android.databinding.Observable dataBindingObservable, int propertyId) {
          if (dataBindingObservable == observableField) {
            asyncEmitter.onNext(observableField.get());
          }
        }
      };

      observableField.addOnPropertyChangedCallback(callback);

      asyncEmitter.setCancellation(() -> observableField.removeOnPropertyChangedCallback(callback));

    }, AsyncEmitter.BackpressureMode.LATEST);
  }
}

代码示例来源:origin: rchodava/datamill

@Override
public ResponseBuilder streamingBodyAsBufferChunks(Func1<Observer<ByteBuffer>, Observable<ByteBuffer>> bodyStreamer) {
  Observable<ByteBuffer> chunkStream = Observable.fromEmitter(emitter -> {
    Subscription subscription = bodyStreamer.call(new PassthroughObserver<>(emitter))
          .doOnNext(buffer -> emitter.onNext(buffer))
          .doOnCompleted(() -> emitter.onCompleted())
          .doOnError(e -> emitter.onError(e))
          .subscribeOn(Schedulers.io())
          .subscribe();
    emitter.setCancellation(subscription::unsubscribe);
  }, Emitter.BackpressureMode.BUFFER);
  this.body = new StreamedChunksBody(chunkStream, Charset.defaultCharset());
  return this;
}

代码示例来源:origin: rchodava/datamill

@Override
public ResponseBuilder streamingJson(Func1<Observer<Json>, Observable<Json>> jsonStreamer) {
  return streamingBody(body ->
      Observable.fromEmitter(emitter -> {
        JsonStreamer streamer = new JsonStreamer(emitter);
        Subscription subscription = jsonStreamer.call(streamer)
            .doOnNext(json -> streamer.onNext(json))
            .doOnCompleted(() -> {
              emitter.onNext("]".getBytes());
              emitter.onCompleted();
            })
            .doOnError(e -> streamer.onError(e))
            .subscribeOn(Schedulers.io())
            .subscribe();
        emitter.setCancellation(subscription::unsubscribe);
      }, Emitter.BackpressureMode.BUFFER));
}

相关文章

Observable类方法