9

Is this code thread-safe?

Observable<String> observable = ... // some observable that calls
                                    // onNext from a background thread

observable
  .scan(new ArrayList<String>(), (List<String> acc, String next) -> {
    acc.add(next);
    return acc;
  })
  .subscribe( list -> {
    // do somethind with sequence of lists
    ...
  });

I'm curious because ArrayList is not a thread-safe data structure.

4

2 に答える 2

4

このコードがスレッドセーフでない場合は、RxJava が壊れているか、Observable ソースが壊れているかのいずれかです。オペレータが再入不可であることは、Rx コントラクトの一部です。

于 2013-09-30T05:49:41.833 に答える