1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 02:59:54 +00:00

Fix URL loader example to use os/spawn

This commit is contained in:
Michael Camilleri 2021-11-11 17:33:25 +09:00
parent 425a0fcf07
commit e1460c65e8
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572

View File

@ -1,10 +1,10 @@
# An example of using Janet's extensible module system # An example of using Janet's extensible module system to import files from
# to import files from URL. To try this, run `janet -l examples/urlloader.janet` # URL. To try this, run `janet -l ./examples/urlloader.janet` from the command
# from the repl, and then: # line, and then at the REPL type:
# #
# (import https://raw.githubusercontent.com/janet-lang/janet/master/examples/colors.janet :as c) # (import https://raw.githubusercontent.com/janet-lang/janet/master/examples/colors.janet :as c)
# #
# This will import a file using curl. You can then try # This will import a file using curl. You can then try:
# #
# (print (c/color :green "Hello!")) # (print (c/color :green "Hello!"))
# #
@ -13,9 +13,9 @@
(defn- load-url (defn- load-url
[url args] [url args]
(def f (file/popen (string "curl " url))) (def p (os/spawn ["curl" url "-s"] :p {:out :pipe}))
(def res (dofile f :source url ;args)) (def res (dofile (p :out) :source url ;args))
(try (file/close f) ([err] nil)) (:wait p)
res) res)
(defn- check-http-url (defn- check-http-url