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

0 votes
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

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

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.
You can also use `take!` with a callback.
Are poll! and offer! available in ClojureScript?


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!
0 votes

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.