-
-
Notifications
You must be signed in to change notification settings - Fork 418
Streaming refactoring #991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
import Data.Machine | ||
import Servant.API.Stream | ||
|
||
instance m ~ IO => ToStreamGenerator (MachineT m k o) o where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tempted to use MonadUnliftIO
6623927
to
14f43ef
Compare
72d00e6
to
6db9f1a
Compare
Last commit adds a simple script to test the streaming stuff, as @alpmestan asked for! Streaming test benchmarksize parameter: 10000000 Servermachines
conduitConduit server is also used for client tests below
Clientmachines
conduit
|
And with pipes: Streaming test benchmarksize parameter: 10000000 Servermachines
pipes
conduitConduit server is also used for client tests below
Clientmachines
pipes
conduit
|
FWIW, test suites fails because of deps (conduit lower bound forces to GHC >= 8.0 (see https://matrix.hackage.haskell.org/package/conduit). Maybe it's time to drop older GHC support (though atm the only reason is deps). |
one idea is to bake |
Me: 🍿 |
go (Effect ms) = Effect (liftIO (fmap go ms)) | ||
go (Yield x s) = Yield x (go s) | ||
|
||
-- This fires e.g. in Client.lhs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Thanks for leaving that note.
9528665
to
51d6cab
Compare
With cookbook Streaming test benchmarksize parameter: 10000000 Server
machines
pipes
conduitConduit server is also used for client tests below
cookbook
Clientmachines
pipes
conduit
cookbook
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I'm completely in line with the approach and don't have much to say. I'll be a little more annoying when the docs etc are done, but great stuffs!
|
||
instance ToSourceIO a [a] where | ||
toSourceIO = source | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we'll want to support all the reasonable container types we directly or indirectly depend on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess things in base
would be enough. But I still wonder how #841 would reshuffle this.
Let's leave an issue to remember about other containers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
d47937c
to
a8e6664
Compare
I'm resurrecting this PR. Hopefully will be able to finish soon. |
How is this PR related to #995 ? Or is it not related at all? I am not sure what this PR does |
@jvanbruegge in short, here I refactor the "drivers". In #995 we'll rethink the type language. |
The key bit iirc is that this (very nice) refactor makes it straightforward to add adapter libs for hooking up to the usual streaming libs, and actually adds some such adapters as well. |
ok, thanks. That was my intuition too, but i wanted to ask just in case I missed something |
Also makes https://github.com/plow-technologies/servant-streaming redundant (well, once streaming glue is there) :) |
@domenkozar not entirely true. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave some feedback on the tutorial/docs, but aside from that LGTM.
doc/tutorial/ApiType.lhs
Outdated
@@ -129,16 +129,23 @@ type UserAPI4 = "users" :> Get '[JSON] [User] | |||
|
|||
### `StreamGet` and `StreamPost` | |||
|
|||
*Note*: Streaming have changed considerably in `servant-0.15`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has changed
doc/tutorial/Client.lhs
Outdated
type ServerStreamAPI = StreamAPI StreamGenerator | ||
type ClientStreamAPI = StreamAPI ResultStream | ||
``` | ||
Note that we use the same `SourceIO` type (this is different from `servant-0.14`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... the same SourceIO
type as on the server-side (...)
doc/tutorial/Client.lhs
Outdated
posStream = client streamAPI | ||
``` | ||
|
||
And here's how to just print out all elements from a `ResultStream`, to give some idea of how to work with them. | ||
We'll get back a `Codensity IO (SourceIO Position)`. The wrapping in | ||
`Codensity` is generally necessary, as `Codensity` let's us to `bracket` things |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets, and remove "to"
doc/tutorial/Server.lhs
Outdated
This simple application returns a stream of `User` values encoded in JSON | ||
format, with each value separated by a newline. In this case, the stream will | ||
consist of the value of `isaac`, followed by the value of `albert`, then the | ||
value of `albert` a third time. Importantly, the stream is written back as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a second time
- Introduce SourceT, which is simple variant of "correct `ListT`". There are another variants possible (like in `streaming`), but I'm not sure there's much real difference. - Introduce `Codensity`. There's a flag if people don't want to depend on `kan-extensions`. - `StreamGenerator` and `ResultStream` are both `SourceT`. `Stream` combinator in `servant-client` uses `Codensity` for CPS. - Add servant-machines, servant-conduit, servant-pipes - Add streaming cookbook: just code, no explanations. - Add a script to run streaming 'benchmarks'
af11720
to
45c1cbd
Compare
StreamReqBody
combinatorpotokistreamingexamples
b
tochunk
.I'll leave implementing docs/foreign for now (i.e. leave dummy instances), as that we'll need to be redone for #841 / #969