简体   繁体   中英

Using ClojureScript core.async channels from Javascript

I'm trying to use a cljs library from a Node.js, Electron project.

A function I'm calling in the cljs library returns a core.async channel object. It looks like this when I console.log :

{
  takes: { head: 0, tail: 0, length: 0, arr: [ <32 empty items> ] },
  dirty_takes: 0,
  puts: { head: 0, tail: 0, length: 0, arr: [ <32 empty items> ] },
  dirty_puts: 0,
  buf: {
    buf: { head: 0, tail: 0, length: 0, arr: [Array] },
    n: 1,
    'cljs$lang$protocol_mask$partition0$': 2,
    'cljs$lang$protocol_mask$partition1$': 0
  },
  closed: false,
  add_BANG_: [Function: G__11914] {
    'cljs$core$IFn$_invoke$arity$1': [Function: G__11914__1],
    'cljs$core$IFn$_invoke$arity$2': [Function: G__11914__2]
  }
}

How can I interact with it from Javascript? How to do something like (take! channel callback) in js?

You can potentially do this if you have access to the cljs.core.async namespace from JS.

;; CLJS
(take! channel callback)
;; JS
cljs.core.async.take_BANG_(channel, function(val) { console.log(val); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM