io.reactivex.subjects.Subject.toSerialized()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(120)

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

Subject.toSerialized介绍

[英]Wraps this Subject and serializes the calls to the onSubscribe, onNext, onError and onComplete methods, making them thread-safe.

The method is thread-safe.
[中]包装此主题,并序列化对onSubscribe、onNext、onError和onComplete方法的调用,使它们具有线程安全性。
该方法是线程安全的。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testDontWrapSerializedSubjectAgain() {
  PublishSubject<Object> s = PublishSubject.create();
  Subject<Object> s1 = s.toSerialized();
  Subject<Object> s2 = s1.toSerialized();
  assertSame(s1, s2);
}

代码示例来源:origin: ch.squaredesk.nova/http

@Override
public <T> Flowable<RpcInvocation<T>> requests(String destination, Class<T> targetType) {
  URL destinationAsLocalUrl;
  try {
    destinationAsLocalUrl = new URL("http", "localhost", destination);
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
  Flowable retVal = mapDestinationToIncomingMessages
      .computeIfAbsent(destination, key -> {
        logger.info("Listening to requests on " + destination);
        Subject<RpcInvocation> stream = PublishSubject.create();
        stream = stream.toSerialized();
        NonBlockingHttpHandler httpHandler = new NonBlockingHttpHandler(destinationAsLocalUrl, messageTranscriber, targetType, stream);
        httpServer.getServerConfiguration().addHttpHandler(httpHandler, destination);
        return stream.toFlowable(BackpressureStrategy.BUFFER)
            .doFinally(() -> {
              mapDestinationToIncomingMessages.remove(destination);
              httpServer.getServerConfiguration().removeHttpHandler(httpHandler);
              logger.info("Stopped listening to requests on " + destination);
            })
            .share();
      });
  return retVal;
}

代码示例来源:origin: k-kagurazaka/rx-property-android

BehaviorSubject.<List<String>>create() :
    PublishSubject.<List<String>>create()
).toSerialized();

相关文章