Welcome! Please see the About page for a little more info on how this works.

+1 vote
in core.async by
recategorized by

Is there a good reason why <!! isn't supported in cljs? If there isn't, wouldn't it be great to add support for <!!?

2 Answers

+1 vote
by

The core.async <!! operation is blocking and will block the current thread. In single-threaded JavaScript, this is not viable.

by
What is a way to get the value from a port then? using go and <! is limiting because the go block returns a channel and not the value.
by
You can also use `take!` with a callback.
by
Are poll! and offer! available in ClojureScript?

https://clojuredocs.org/clojure.core.async/poll!
https://clojuredocs.org/clojure.core.async/offer!

If so, you can use those, if not, I wonder why not, since they are not blocking, seems they could be implemented in JS as well.

EDIT: They are!
by
> In single-threaded JavaScript, this is not viable.

But using it in a Web Worker is reasonable.
0 votes
by

You can use poll! and offer! instead, they are the non-blocking equivalent. Just keep in mind, they will not "wait" for a value to be available, so you need to keep polling yourself, or be sure there should be one.

Like others have said, <!! doesn't make sense in the context of JavaScript, since you never want to block the main thread, and it would need too in order to perform the "waiting" operation.

There also exists take!, if you don't want to implement polling yourself, it will do it for you (well more efficiently), and call you back when the value is available with it.

by
> <!! doesn't make sense in the context of JavaScript, since you never want to block the main thread

It makes sense in the context of using a Web Worker, which performs tasks without interfering with the user interface.
...