Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x: Add RxJavaPlugins.createExecutorScheduler #7306

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Aug 2, 2021

This PR adds the RxJavaPlugins.createExecutorScheduler that instantiates the already existing ExecutorScheduler independent of the Schedulers class. The from methods in the Schedulers class are now pointing to this new method.

Resolves #7305
Related #7300

@akarnokd akarnokd added this to the 3.1 milestone Aug 2, 2021
@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #7306 (aff7834) into 3.x (e24e725) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #7306      +/-   ##
============================================
- Coverage     99.53%   99.52%   -0.02%     
- Complexity     6783     6786       +3     
============================================
  Files           751      751              
  Lines         47489    47490       +1     
  Branches       6378     6378              
============================================
- Hits          47268    47263       -5     
- Misses          100      103       +3     
- Partials        121      124       +3     
Impacted Files Coverage Δ
...va/io/reactivex/rxjava3/plugins/RxJavaPlugins.java 100.00% <100.00%> (ø)
...va/io/reactivex/rxjava3/schedulers/Schedulers.java 100.00% <100.00%> (ø)
...l/operators/observable/ObservableFlatMapMaybe.java 89.43% <0.00%> (-8.46%) ⬇️
...nternal/operators/observable/ObservableCreate.java 96.58% <0.00%> (-3.42%) ⬇️
.../operators/observable/ObservableFlatMapSingle.java 94.44% <0.00%> (-1.59%) ⬇️
...ators/observable/ObservableFlatMapCompletable.java 98.52% <0.00%> (-1.48%) ⬇️
...va3/internal/operators/parallel/ParallelRunOn.java 98.53% <0.00%> (-1.47%) ⬇️
...java3/internal/operators/flowable/FlowableZip.java 98.97% <0.00%> (-1.03%) ⬇️
.../operators/maybe/MaybeFlatMapIterableFlowable.java 99.18% <0.00%> (-0.82%) ⬇️
...ternal/operators/observable/ObservableFlatMap.java 97.87% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e24e725...aff7834. Read the comment docs.

@akarnokd akarnokd merged commit 5b0dd58 into ReactiveX:3.x Aug 2, 2021
@akarnokd akarnokd deleted the CreateExecutorScheduler branch August 2, 2021 10:55
@matthew-swift
Copy link

Hi there. I'm not sure this change is working as expected. The following code creates the standard default schedulers:

ExecutorService executor = Executors.newSingleThreadExecutor();
Scheduler scheduler = RxJavaPlugins.createExecutorScheduler(executor, false, false);
Flowable.intervalRange(1, 10, 1, 1, TimeUnit.SECONDS, scheduler)
        .blockingForEach(System.out::println);
executor.shutdown();

But according to the new Javadoc it should not trigger the creation of the default schedulers:

It is possible to wrap an Executor into a Scheduler without triggering the initialization of all the standard schedulers by using the RxJavaPlugins.createExecutorScheduler(Executor, boolean, boolean) method before the Schedulers class itself is accessed.

It clearly will though because the ExecutorScheduler class contains a static reference HELPER which references Schedulers.single() which then initializes all of the default schedulers as observed by putting a breakpoint in the static initializer block on line 80 of Schedulers.

Apologies if I'm misunderstanding the intent of this change. If I am then that may indicate that the new Javadoc is a bit misleading.

@akarnokd
Copy link
Member Author

Indeed the method should not trigger that initialization. I'll work out how to break that cycle and post a fix shortly.

@matthew-swift
Copy link

Thanks for your quick response David. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.x: Add RxJavaPlugins.createExecutorScheduler
3 participants