Fix #1507: support calling getName on virtual thread

This commit is contained in:
Rahuλ Dé 2023-03-02 14:10:58 +00:00 committed by GitHub
parent b8a0520b93
commit 9e004edefe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View file

@ -7,6 +7,10 @@ A preview of the next release can be installed from
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
## Unreleased
- [#1507](https://github.com/babashka/babashka/issues/1507): Expose methods on java.lang.VirtualThread ([@lispyclouds](https://github.com/lispyclouds))
## 1.2.174 (2023-03-01)
- Use GraalVM 22.3.1 on JDK 19.0.2. This adds virtual thread support. See [demo](https://twitter.com/borkdude/status/1572222344684531717).

View file

@ -20,6 +20,7 @@
:windows (complement (some-fn :skip-windows :flaky))
:non-flaky (complement :flaky)
:flaky :flaky}
:jvm-opts ["--enable-preview"]
:dependencies [[org.clojure/clojure "1.11.1"]
[borkdude/edamame "1.1.17"]
[borkdude/graal.locking "0.0.2"]

View file

@ -677,6 +677,8 @@
java.util.Iterator
(instance? javax.crypto.SecretKey v)
javax.crypto.SecretKey
(instance? java.lang.Thread v)
java.lang.Thread
;; keep commas for merge friendliness
,,,)))
m (assoc m (list 'quote 'clojure.lang.Var) 'sci.lang.Var)

View file

@ -0,0 +1,16 @@
(ns babashka.interop-test
(:require
[babashka.test-utils :as test-utils]
[clojure.edn :as edn]
[clojure.test :as test :refer [deftest is testing]]))
(defn bb [input & args]
(test-utils/normalize
(edn/read-string
{:readers *data-readers*
:eof nil}
(apply test-utils/bb (when (some? input) (str input)) (map str args)))))
(deftest vthreads-test
(testing "can invoke methods on java.lang.VirtualThread"
(is (= "" (bb nil "(set-agent-send-off-executor! (java.util.concurrent.Executors/newVirtualThreadPerTaskExecutor)) @(future (.getName (Thread/currentThread)))")))))