Skip to content

Commit f6b2a7b

Browse files
update clojure and groovy code to subscriptions changes
1 parent 538547b commit f6b2a7b

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
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

0 commit comments

Comments
 (0)