@@ -60,15 +60,16 @@ public Disposable schedule(@NonNull final Runnable action, long delayTime, @NonN
60
60
* @return the ScheduledRunnable instance
61
61
*/
62
62
public Disposable scheduleDirect (final Runnable run , long delayTime , TimeUnit unit ) {
63
- Runnable decoratedRun = RxJavaPlugins .onSchedule (run );
63
+ ScheduledDirectTask task = new ScheduledDirectTask ( RxJavaPlugins .onSchedule (run ) );
64
64
try {
65
65
Future <?> f ;
66
- if (delayTime <= 0 ) {
67
- f = executor .submit (decoratedRun );
66
+ if (delayTime <= 0L ) {
67
+ f = executor .submit (task );
68
68
} else {
69
- f = executor .schedule (decoratedRun , delayTime , unit );
69
+ f = executor .schedule (task , delayTime , unit );
70
70
}
71
- return Disposables .fromFuture (f );
71
+ task .setFuture (f );
72
+ return task ;
72
73
} catch (RejectedExecutionException ex ) {
73
74
RxJavaPlugins .onError (ex );
74
75
return EmptyDisposable .INSTANCE ;
@@ -85,10 +86,11 @@ public Disposable scheduleDirect(final Runnable run, long delayTime, TimeUnit un
85
86
* @return the ScheduledRunnable instance
86
87
*/
87
88
public Disposable schedulePeriodicallyDirect (final Runnable run , long initialDelay , long period , TimeUnit unit ) {
88
- Runnable decoratedRun = RxJavaPlugins .onSchedule (run );
89
+ ScheduledDirectPeriodicTask task = new ScheduledDirectPeriodicTask ( RxJavaPlugins .onSchedule (run ) );
89
90
try {
90
- Future <?> f = executor .scheduleAtFixedRate (decoratedRun , initialDelay , period , unit );
91
- return Disposables .fromFuture (f );
91
+ Future <?> f = executor .scheduleAtFixedRate (task , initialDelay , period , unit );
92
+ task .setFuture (f );
93
+ return task ;
92
94
} catch (RejectedExecutionException ex ) {
93
95
RxJavaPlugins .onError (ex );
94
96
return EmptyDisposable .INSTANCE ;
@@ -145,6 +147,16 @@ public void dispose() {
145
147
}
146
148
}
147
149
150
+ /**
151
+ * Shuts down the underlying executor in a non-interrupting fashion.
152
+ */
153
+ public void shutdown () {
154
+ if (!disposed ) {
155
+ disposed = true ;
156
+ executor .shutdown ();
157
+ }
158
+ }
159
+
148
160
@ Override
149
161
public boolean isDisposed () {
150
162
return disposed ;
0 commit comments