Adding ScheduledAction to the official API #2579
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've copied the internal
ScheduledAction
into the publicrx.schedulers
package to allow customScheduler
implementors in other projects to take advantage of its correct unsubscription management.I've removed the internal
ScheduledAction
. Since relying on internal features are discouraged anyway, use places outside RxJava need to be updated. Deprecating it doesn't work because the class is final and the internals now return the newrx.schedulers.ScheduledAction
and would result inClassCastException
anyway.I've introduced a system-wide parameter
io.reactivex.scheduler.interrupt-on-unsubscribe
to enable interruption globally. In addition, eachScheduledAction
has its ownsetInterruptOnUnsubscribe
which allows enabling/disabling interrupts on an individual basis (overrides the default from the system-wide parameter above for the instance).I've also added detailed documentation to it and (while I was in the mood) to the
NewThreadWorker
.There is a slight performance drawback now since setting the current thread id at the beginning of the
run()
method has to preserve the interruptible flag thus it has to perform a CAS instead of a 32-bit lazySet. Also note that the instance size change is unavoidable because a reference+int has the same allocation cost as a single long (there is no byte-atomics).