Fork me on GitHub
#core-async
<
2016-01-26
>
andrewboltachev10:01:12

Hi. Is it possible to ​synchronize​ AJAX request with core.async somehow (taking into account <!! doesn't exist in CLJS)?

sander11:01:58

@andrewboltachev: what do you mean by synchronize? you can use a promise chan and put the XMLHttpRequest result to it, and work with that in a go block

andrewboltachev11:01:46

I mean to have function like (defn return-data-from-resource [url] ) which returns data when it arrives

sander11:01:52

@andrewboltachev: not directly in cljs, but you can make it return a (promise) chan that you can process synchronously from within a go block

andrewboltachev11:01:25

I just remember I've seen sth like that

andrewboltachev11:01:47

May be not, of course

andrewboltachev11:01:58

Well, I'll try to think up a solution

sander11:01:00

@andrewboltachev: you can use the synchronous xmlhttprequest api, but can't recommend that. otherwise, there's no way to do things that couldn't be done in javascript, go just rewrites your code so that you can reason about it like it's synchronous

andrewboltachev11:01:32

yep I understand. in fact, in my task I would be invoking callback anyway (but I need to ditch few items in a row). I believe I might find a solution with core.async. Thanks @sander

hlship23:01:52

I'm doing something just a bit odd: I want to do somelike like an alt! or alts!, but I have one fixed channel where I do operation A when I get value, and then some number of other channels (that change over time) wher I do operation B.

hlship23:01:50

Hm. I guess I could use the new poll! function.

hlship23:01:39

But less than ideal, as I have to distinguish between "closed" and "nothing ready".