Fork me on GitHub
#core-async
<
2017-12-04
>
bhurlow15:12:40

I’m stuck on what appears to be a simple question around core.async, maybe someone here can help out:

bhurlow15:12:10

I want to asynchronously read and handle incoming data in a web-application via a streaming http request

bhurlow15:12:28

I can convert the incoming body to a channel via lazy-seq like this: (async/to-chan (line-seq (reader body)))

bhurlow15:12:33

but that blocks

bhurlow15:12:11

how can I asynchronously put data onto a channel coming from an InputStream?

mccraigmccraig15:12:15

@bhurlow InputStreams have a blocking API so you will need to use a thread - depending on your webserver you may be able to get it to give you some async friendly structure though - core.async channel, manifold promise etc

bhurlow15:12:18

@mccraigmccraig ok thanks, am using aleph so seems like manifold stream might be possible

mccraigmccraig15:12:24

@bhurlow i'm using aleph with #yada - async is with manifold deferreds, which compose nicely with manifold.deferred/chain or cats.core/mlet

bhurlow15:12:53

@mccraigmccraig what about for when the incoming body stream is continuous? In my case I can’t necessarily deref the body as it’s not completed until the connection is closed

bhurlow15:12:58

or rather, I’d prefer to start processing the incoming before totally buffered

mccraigmccraig15:12:12

yada has some nice support for streaming mime-multipart uploads - it does all the separator and part recognition and hands your callback fragments... not sure if there is a manifold-stream interface to it now (this should probably move to #yada 🙂 )

bhurlow15:12:36

ok cool, will investigate there