Closed grzm closed 10 months ago
Class added. Master version can be tested with:
bash <(curl https://raw.githubusercontent.com/babashka/babashka/master/install) --dev-build --dir /tmp
Thanks, @borkdude ! For what it's worth, testing prompted by @lispyclouds 's suggestion in slack with a shipping version of babashka (v1.3.181) confirms I can close the result of ScheduledExecutorService.schedule
out of the box. I haven't confirmed whether any reflection warning is generated.
% bb
Babashka v1.3.181 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (import (java.util.concurrent Executors))
java.util.concurrent.Executors
user=> (import (java.util.concurrent ThreadFactory))
java.util.concurrent.ThreadFactory
user=> (defonce ^:private scheduled-executor-service
(delay
(Executors/newScheduledThreadPool 1 (reify ThreadFactory
(newThread [_ r]
(doto (Thread. r)
(.setName "cognitect.aws-api.credentials-provider")
(.setDaemon true)))))))
#'user/scheduled-executor-service
user=> (import (java.util.concurrent TimeUnit))
java.util.concurrent.TimeUnit
user=> (def f (.schedule @scheduled-executor-service (fn [] (prn :yup)) 5 TimeUnit/SECONDS))
#'user/f
user=> :yup
f
#object[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask 0x4f0d4632 "java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@4f0d4632[Completed normally]"]
user=> (.cancel f true)
false
user=> (def f (.schedule @scheduled-executor-service (fn [] (prn :yup)) 5 TimeUnit/SECONDS))
#'user/f
user=> (.cancel f true)
true
aws-api supports caching and auto-refreshing credentials:
https://github.com/cognitect-labs/aws-api/blob/7352ec647ff19f6a14cbbfc5e581c48a8183ebf1/src/cognitect/aws/credentials.clj#L76-L103
awyeah-api does not currently support this feature as babashka did not include the requisite Java classes at the time of initial development, namely:
java.lang.Runnable
java.util.concurrent.ThreadFactory
java.util.concurrent.ScheduledFuture
java.util.concurrent.ScheduledExecutorService
Babashka added support for some of these classes:
java.lang.Runnable
(https://github.com/babashka/babashka/commit/ea4f56886d6728a51505e8c23da2ad49174f64d9)java.util.concurrent.ThreadFactory
(https://github.com/babashka/babashka/commit/5b42de70d81b4057b21a8c9b3a801df3381516c1)java.util.concurrent.ScheduledFuture
java.util.concurrent.ScheduledExecutorService
(https://github.com/babashka/babashka/commit/96d93d3940c28e5e180b44dc2c506e4348a47ac5)So, as of now it looks like we're only missing
java.util.concurrent.ScheduledFuture
to support refreshable creds in in the same manner as aws-api.