Skip to content

Commit 2954df3

Browse files
committed
Remove when-class for Java 8 classes
1 parent 33cfd9e commit 2954df3

File tree

5 files changed

+36
-64
lines changed

5 files changed

+36
-64
lines changed

README.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,9 @@ Manifold can use any transducer, which are applied via `transform`. It also pro
121121

122122
A Clojurescript implementation of Manifold can be found here: [dm3/manifold-cljs](https://github.com/dm3/manifold-cljs).
123123

124-
### Older Java support
125-
126-
Manifold includes support for a few classes introduced in Java 8:
127-
`java.util.concurrent.CompletableFuture` and `java.util.stream.BaseStream`.
128-
Support for Java 8+ is detected automatically at compile time; if you are
129-
AOT compiling Manifold on Java 8 or newer, but will be running the compiled
130-
jar with a Java 7 or older JRE, you will need to disable them, by
131-
setting the JVM option `"manifold.disable-jvm8-primitives"`, either at the
132-
command line with
133-
134-
-Dmanifold.disable-jvm8-primitives=true
135-
136-
or by adding
137-
138-
:jvm-opts ["-Dmanifold.disable-jvm8-primitives=true"]
139-
140-
to your application's project.clj.
141-
142124

143125
### License
144126

145-
Copyright © 2014-2021 Zach Tellman
127+
Copyright © 2014-2022 Zach Tellman
146128

147129
Distributed under the MIT License.

src/manifold/deferred.clj

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
Future
2323
TimeoutException
2424
TimeUnit
25-
ConcurrentHashMap
2625
CountDownLatch
27-
Executor]
26+
Executor
27+
CompletableFuture]
2828
[java.util.concurrent.locks
2929
Lock]
3030
[java.util.concurrent.atomic
31-
AtomicBoolean
3231
AtomicInteger
3332
AtomicLong]
3433
[clojure.lang
@@ -1259,20 +1258,18 @@
12591258
(success! d msg))))
12601259
d))))
12611260

1262-
(utils/when-class java.util.concurrent.CompletableFuture
1261+
(extend-protocol Deferrable
12631262

1264-
(extend-protocol Deferrable
1265-
1266-
java.util.concurrent.CompletableFuture
1267-
(to-deferred [f]
1268-
(let [d (deferred)]
1269-
(.handle ^java.util.concurrent.CompletableFuture f
1270-
(reify java.util.function.BiFunction
1271-
(apply [_ val err]
1272-
(if (nil? err)
1273-
(success! d val)
1274-
(error! d err)))))
1275-
d))))
1263+
CompletableFuture
1264+
(to-deferred [f]
1265+
(let [d (deferred)]
1266+
(.handle ^CompletableFuture f
1267+
(reify java.util.function.BiFunction
1268+
(apply [_ val err]
1269+
(if (nil? err)
1270+
(success! d val)
1271+
(error! d err)))))
1272+
d)))
12761273

12771274
;;;
12781275

src/manifold/stream/iterator.clj

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
[java.util
1313
Iterator]
1414
[java.util.concurrent.atomic
15-
AtomicReference]))
15+
AtomicReference]
16+
(java.util.stream BaseStream)))
1617

1718
(s/def-source IteratorSource
1819
[^Iterator iterator
@@ -63,19 +64,14 @@
6364
d)))))
6465

6566
(extend-protocol s/Sourceable
66-
67-
java.util.Iterator
67+
Iterator
6868
(to-source [iterator]
6969
(->IteratorSource
7070
iterator
71-
(AtomicReference. (d/success-deferred true)))))
72-
73-
(utils/when-class java.util.stream.BaseStream
71+
(AtomicReference. (d/success-deferred true))))
7472

75-
(extend-protocol s/Sourceable
76-
77-
java.util.stream.BaseStream
78-
(to-source [stream]
79-
(->IteratorSource
80-
(.iterator ^java.util.stream.BaseStream stream)
81-
(AtomicReference. (d/success-deferred true))))))
73+
BaseStream
74+
(to-source [stream]
75+
(->IteratorSource
76+
(.iterator ^BaseStream stream)
77+
(AtomicReference. (d/success-deferred true)))))

src/manifold/utils.clj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,11 @@
121121
`(do ~@body)))
122122

123123
(defmacro when-class [class & body]
124-
(let [disable-property (System/getProperty "manifold.disable-jvm8-primitives")
125-
disabled? (and disable-property (not= disable-property "false"))]
126-
(when (and (not disabled?)
127-
(try
128-
(Class/forName (name class))
129-
(catch Throwable e
130-
)))
131-
`(do ~@body))))
124+
(when (try
125+
(Class/forName (name class))
126+
(catch Exception _
127+
false))
128+
`(do ~@body)))
132129

133130
;;;
134131

test/manifold/deferred_test.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[clojure.test :refer :all]
77
[manifold.test-utils :refer :all]
88
[manifold.deferred :as d]
9-
[manifold.executor :as ex]))
9+
[manifold.executor :as ex])
10+
(:import (java.util.concurrent CompletableFuture)))
1011

1112
(defmacro future' [& body]
1213
`(d/future
@@ -271,14 +272,13 @@
271272
(deftest test-coercion
272273
(is (= 1 (-> 1 clojure.core/future d/->deferred deref)))
273274

274-
(utils/when-class java.util.concurrent.CompletableFuture
275-
(let [f (java.util.concurrent.CompletableFuture.)]
276-
(.obtrudeValue f 1)
277-
(is (= 1 (-> f d/->deferred deref))))
275+
(let [f (CompletableFuture.)]
276+
(.obtrudeValue f 1)
277+
(is (= 1 (-> f d/->deferred deref))))
278278

279-
(let [f (java.util.concurrent.CompletableFuture.)]
280-
(.obtrudeException f (Exception.))
281-
(is (thrown? Exception (-> f d/->deferred deref))))))
279+
(let [f (CompletableFuture.)]
280+
(.obtrudeException f (Exception.))
281+
(is (thrown? Exception (-> f d/->deferred deref)))))
282282

283283
(deftest test-finally
284284
(let [target-d (d/deferred)

0 commit comments

Comments
 (0)