clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Atiq Gauri 2021-04-04T12:45:05.475100Z

I am trying to use a npm package in cljs called "https://github.com/sebhildebrandt/systeminformation" most of its function are async and some are non-async but I am unable to use async function, everything else work fine

RELATED IMPORTS

[clojure.core.async :as async] 
["systeminformation" :as systeminformation]
Code I am trying to run
(comment

  (systeminformation/version) // WORKS FINE 
  
  (async/go
    (async/<! (systeminformation/cpu))) // Gives me error 
  )
ERROR:
INFO [mutesync.inspect.electron.background.main:30] - STACK
 TypeError: c.cljs$core$async$impl$protocols$ReadPort$take_BANG_$arity$2 is not a function
    at cljs$core$async$impl$ioc_helpers$take_BANG_ (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc_helpers.cljs:52:1)
    at switch__47338__auto__ (<eval>:8:52)
    at <eval>:32:29
    at Function.fexpr__47378 [as cljs$core$IFn$_invoke$arity$1] (<eval>:54:4)
    at Object.cljs$core$async$impl$ioc_helpers$run_state_machine [as run_state_machine] (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc
_helpers.cljs:43:3)
    at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc_helpers.cljs:45:1)
    at <eval>:84:67
    at Immediate.cljs$core$async$impl$dispatch$process_messages (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\dispatch.cljs:26:7)
    at processImmediate (internal/timers.js:456:21)
ERROR [mutesync.inspect.electron.background.main:68] - uncaught error
TypeError: c.cljs$core$async$impl$protocols$ReadPort$take_BANG_$arity$2 is not a function

alpox 2021-04-04T12:52:21.475400Z

Async functions from javascript are functions which return a javascript Promise. async.core would require a clojurescript core.async channel to work. With promises you can work as normally with js promises or use a helper library like https://github.com/funcool/promesa

Atiq Gauri 2021-04-04T13:07:38.475700Z

yes but I wanted to avoid any library use this works too:

(.then (js/Promise.resolve (systeminformation/cpu))
         #(log/spy (js->clj %)))

p-himik 2021-04-04T13:25:55.475900Z

Why do you use .resolve? Unwrap the call to (.../cpu)`.

p-himik 2021-04-04T13:28:03.476100Z

(-> (systeminformation/cpu) (.then (fn [result] ...)))

🙌 1
✅ 1