Created
March 12, 2021 11:32
-
-
Save dainiusjocas/0d49f291ae3bf32cd42ff0fe6fbb367b to your computer and use it in GitHub Desktop.
GraalVM Javascript context locking to enable multithreaded access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (org.graalvm.polyglot Value Context HostAccess) | |
(java.util Map) | |
(org.graalvm.polyglot.proxy ProxyObject)) | |
(let [js-fn-constructor (fn [^String script] | |
(let [^Context ctx (.build (Context/newBuilder (into-array String ["js"]))) | |
^Value f (.eval ctx "js" script)] | |
(fn [value] | |
(locking ctx | |
(.execute f (object-array [value])))))) | |
js-fn (js-fn-constructor "(val) => console.log(val)")] | |
(js-fn {:foo "bar"})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The multithreaded Javascript is described here https://medium.com/graalvm/multi-threaded-java-javascript-language-interoperability-in-graalvm-2f19c1f9c37b.