Skip to content

Commit 96eebf2

Browse files
Merge pull request #188 from benjchristensen/issue-173
Subscriptions cleanup
2 parents 7d22feb + f6b2a7b commit 96eebf2

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

language-adaptors/rxjava-clojure/src/examples/clojure/rx/lang/clojure/examples/rx_examples.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns rx.lang.clojure.examples.rx-examples
2-
(:import rx.Observable)
2+
(:import rx.Observable rx.subscriptions.Subscriptions)
33
(:require [clj-http.client :as http]))
44

55
; NOTE on naming conventions. I'm using camelCase names (against clojure convention)
@@ -62,7 +62,7 @@
6262
(-> observer .onCompleted)
6363
; return a NoOpSubsription since this blocks and thus
6464
; can't be unsubscribed from
65-
(Observable/noOpSubscription))))
65+
(Subscriptions/empty))))
6666

6767
; To see output
6868
(comment
@@ -81,7 +81,7 @@
8181
; after sending all values we complete the sequence
8282
(-> observer .onCompleted))]
8383
; return a subscription that cancels the future
84-
(Observable/createSubscription #(future-cancel f))))))
84+
(Subscriptions/create #(future-cancel f))))))
8585

8686
; To see output
8787
(comment
@@ -100,7 +100,7 @@
100100
; after sending response to onnext we complete the sequence
101101
(-> observer .onCompleted))]
102102
; a subscription that cancels the future if unsubscribed
103-
(Observable/createSubscription #(future-cancel f))))))
103+
(Subscriptions/create #(future-cancel f))))))
104104

105105
; To see output
106106
(comment
@@ -147,7 +147,7 @@
147147
(-> observer .onCompleted)
148148
(catch Exception e (-> observer (.onError e))))) ]
149149
; a subscription that cancels the future if unsubscribed
150-
(Observable/createSubscription #(future-cancel f))))))
150+
(Subscriptions/create #(future-cancel f))))))
151151

152152
(defn getVideoBookmark [userId, videoId]
153153
"Asynchronously fetch bookmark for video
@@ -165,7 +165,7 @@
165165
(-> observer .onCompleted)
166166
(catch Exception e (-> observer (.onError e)))))]
167167
; a subscription that cancels the future if unsubscribed
168-
(Observable/createSubscription #(future-cancel f))))))
168+
(Subscriptions/create #(future-cancel f))))))
169169

170170
(defn getVideoMetadata [videoId, preferredLanguage]
171171
"Asynchronously fetch movie metadata for a given language
@@ -190,7 +190,7 @@
190190
(-> observer .onCompleted)
191191
(catch Exception e (-> observer (.onError e))))) ]
192192
; a subscription that cancels the future if unsubscribed
193-
(Observable/createSubscription #(future-cancel f))))))
193+
(Subscriptions/create #(future-cancel f))))))
194194

195195

196196
(defn getVideoForUser [userId videoId]
@@ -256,7 +256,7 @@
256256
; after sending response to onNext we complete the sequence
257257
(-> observer .onCompleted))]
258258
; a subscription that cancels the future if unsubscribed
259-
(Observable/createSubscription #(future-cancel f))))))
259+
(Subscriptions/create #(future-cancel f))))))
260260

261261
; To see output
262262
(comment

language-adaptors/rxjava-clojure/src/examples/clojure/rx/lang/clojure/examples/video_example.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns rx.lang.clojure.examples.video-example
2-
(:import [rx Observable Observer Subscription]))
2+
(:import [rx Observable Observer Subscription] rx.subscriptions.Subscriptions))
33

44
; Adapted from language-adaptors/rxjava-groovy/src/examples/groovy/rx/lang/groovy/examples/VideoExample.groovy
55

@@ -93,7 +93,7 @@
9393
[f]
9494
(Observable/create (fn [^Observer observer]
9595
(let [f (future (f observer))]
96-
(Observable/createSubscription #(future-cancel f))))))
96+
(Subscriptions/create #(future-cancel f))))))
9797

9898
(defn ^Observable get-list-of-lists
9999
"
@@ -122,7 +122,7 @@
122122
(dotimes [i 50]
123123
(.onNext observer (+ (* position 1000) i)))
124124
(.onCompleted observer)
125-
(Observable/noOpSubscription))))
125+
(Subscriptions/empty))))
126126

127127
(comment (.subscribe (video-list->videos (video-list 2)) println))
128128

@@ -133,7 +133,7 @@
133133
:actors ["actor1" "actor2"]
134134
:duration 5428 })
135135
(.onCompleted observer)
136-
(Observable/noOpSubscription))))
136+
(Subscriptions/empty))))
137137

138138
(comment (.subscribe (video->metadata 10) println))
139139

language-adaptors/rxjava-groovy/src/examples/groovy/rx/lang/groovy/examples/RxExamples.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package rx.lang.groovy.examples;
1818
import rx.Observable;
1919
import rx.Observer;
2020
import rx.Subscription;
21+
import rx.subscriptions.Subscriptions;
2122
import rx.util.functions.Func1;
2223

2324
// --------------------------------------------------
@@ -86,9 +87,9 @@ def customObservableBlocking() {
8687
}
8788
// after sending all values we complete the sequence
8889
observer.onCompleted();
89-
// return a NoOpSubsription since this blocks and thus
90+
// return an empty subscription since this blocks and thus
9091
// can't be unsubscribed from
91-
return Observable.noOpSubscription();
92+
return Subscriptions.empty();
9293
};
9394
});
9495
}
@@ -151,7 +152,7 @@ def fetchWikipediaArticleAsynchronously(String... wikipediaArticleNames) {
151152
}
152153
observer.onCompleted();
153154
}
154-
return Observable.noOpSubscription();
155+
return Subscriptions.empty();
155156
});
156157
}
157158

@@ -218,7 +219,7 @@ def fetchWikipediaArticleAsynchronouslyWithErrorHandling(String... wikipediaArti
218219
observer.onError(e);
219220
}
220221
}
221-
return Observable.noOpSubscription();
222+
return Subscriptions.empty();
222223
});
223224
}
224225

rxjava-core/src/main/java/rx/subscriptions/Subscriptions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class Subscriptions {
1212
* @return {@link Subscription}
1313
*/
1414
public static Subscription empty() {
15-
return new EmptySubscription();
15+
return EMPTY;
1616
}
1717

1818
/**
1919
* A {@link Subscription} implemented via a Func
2020
*
2121
* @return {@link Subscription}
2222
*/
23-
public static Subscription createSubscription(final Action0 unsubscribe) {
23+
public static Subscription create(final Action0 unsubscribe) {
2424
return new Subscription() {
2525

2626
@Override
@@ -36,7 +36,7 @@ public void unsubscribe() {
3636
*
3737
* @return {@link Subscription}
3838
*/
39-
public static Subscription createSubscription(final Object unsubscribe) {
39+
public static Subscription create(final Object unsubscribe) {
4040
final FuncN<?> f = Functions.from(unsubscribe);
4141
return new Subscription() {
4242

@@ -51,8 +51,8 @@ public void unsubscribe() {
5151
/**
5252
* A {@link Subscription} that does nothing when its unsubscribe method is called.
5353
*/
54-
private static class EmptySubscription implements Subscription {
54+
private static Subscription EMPTY = new Subscription() {
5555
public void unsubscribe() {
5656
}
57-
}
57+
};
5858
}

0 commit comments

Comments
 (0)