@Override
    public void request(long n) {
      if (once) {
        return;
      }
      if (n < 0L) {
        throw new IllegalStateException("n >= required but it was " + n);
      }
      if (n != 0L) {
        once = true;
        Subscriber<? super T> a = actual;
        if (a.isUnsubscribed()) {
          return;
        }
        T v = value;
        try {
          a.onNext(v);
        } catch (Throwable e) {
          Exceptions.throwOrReport(e, a, v);
          return;
        }

        if (a.isUnsubscribed()) {
          return;
        }
        a.onCompleted();
      }
    }
 @Override
 public void call() {
   Subscriber<? super T> a = actual;
   if (a.isUnsubscribed()) {
     return;
   }
   T v = value;
   try {
     a.onNext(v);
   } catch (Throwable e) {
     Exceptions.throwOrReport(e, a, v);
     return;
   }
   if (a.isUnsubscribed()) {
     return;
   }
   a.onCompleted();
 }
 @Override
 public void request(long n) {
   if (n < 0L) {
     throw new IllegalArgumentException("n >= 0 required but it was " + n);
   }
   if (n != 0 && compareAndSet(false, true)) {
     actual.add(onSchedule.call(this));
   }
 }
예제 #4
0
  @Override
  public void call(final Subscriber<? super T> subscriber) {

    try {

      // create the resource
      final Resource resource = resourceFactory.call();
      // create an action/subscription that disposes only once
      final DisposeAction<Resource> disposeOnceOnly =
          new DisposeAction<Resource>(dispose, resource);
      // dispose on unsubscription
      subscriber.add(disposeOnceOnly);
      // create the observable
      final Observable<? extends T> source =
          observableFactory
              // create the observable
              .call(resource);
      final Observable<? extends T> observable;
      // supplement with on termination disposal if requested
      if (disposeEagerly)
        observable =
            source
                // dispose on completion or error
                .doOnTerminate(disposeOnceOnly);
      else observable = source;
      try {
        // start
        observable.unsafeSubscribe(Subscribers.wrap(subscriber));
      } catch (Throwable e) {
        Throwable disposeError = disposeEagerlyIfRequested(disposeOnceOnly);
        Exceptions.throwIfFatal(e);
        Exceptions.throwIfFatal(disposeError);
        if (disposeError != null)
          subscriber.onError(new CompositeException(Arrays.asList(e, disposeError)));
        else
          // propagate error
          subscriber.onError(e);
      }
    } catch (Throwable e) {
      // then propagate error
      Exceptions.throwOrReport(e, subscriber);
    }
  }
 @Override
 public void call(Subscriber<? super T> s) {
   s.setProducer(new ScalarAsyncProducer<T>(s, value, onSchedule));
 }