| CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 422
Change definition of StreamGenerator #959
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
|
I don't think the build failure is caused by my code |
|
Changing the class to use a fundep makes sense, as you explained. But, I don't see what the move to a StreamGenerator parameterized over MonadUnliftIO buys you? Especially since the usage you make of it seems to all be in the case where it is specialized back to IO anyway? |
|
The instance I have there currently is just for easy usage with IO. My issue is because my App base monad is a ReaderT IO and I need the monadic context for my response. With MonadUnliftIO I can do that |
|
I confess I don't understand why |
|
Because the return value of the function is runConduit returns |
|
Yeah, UnliftIO is not needed when you let the functions return plain IO This means the ToStreamGenerator class would have to pass the monad too |
|
Right. You won't be able to write the instance in general. You can only write it for specific I suspect that what you've written doesn't do how you expect. The only conduits you will be able to use, because of the universal quantification, are things that work over any (i.e. what you ran into above). |
|
Oh and I see the Reader issue now. Yeah, you won't be able to pass in a conduit over |
|
I see, thank you. I will try that |
|
Regarding CI, yes the build fails with the oldest GHC that we test on but that's been the case for some time, it's not because of your patch. We will soon slide the window, getting rid of that one and adding 8.4. |
670b4ee to
323d7e2
Compare
|
I squashed my commits as I was now able to write a working conduit instance that streamed a video over a normal servant StreamGet endpoint: instance ToStreamGenerator (ConduitT () o (ResourceT IO) ()) o where
toStreamGenerator s = StreamGenerator $ \a b -> runConduitRes $ s .| op a b
where op :: (o -> IO ()) -> (o -> IO ()) -> ConduitT o Void (ResourceT IO) ()
op start rest = do
takeC 1 .| mapM_C (liftIO . start)
mapM_C $ liftIO . restCode using the instance: type FileStream = ConduitT () ByteString (ResourceT IO) ()
serveFile :: Id -> Server (StreamGet NoFraming OggVideo FileStream)
serveFile id = except404 (getFilePath id) >>= pure . Conduit.sourceFile
getFilePath :: (DB.MonadDB m) => Id -> m (Either Text FilePath)
getFilePath id = DB.getVideoFile id >>= \case
Left e -> pure $ Left e
Right (DBEntry _ VideoFile{ path }) -> pure . Right . toFilePath . prefixPath $ path |
|
And CI passes except for the oldest GHC π |
|
Streaming files requires a basic |
|
@jvanbruegge Yes, please do feel free to add it. In fact, in previous discussions I came to realize that for many many common streaming scenarios, this is the "framing strategy" we would need. So this PR looks to me like the perfect excuse for adding it. :-) |
|
Done, though I am not entirely sure about FramingUnrender. Test do pass. |
|
@gbaz How does this PR look to you now? |
|
I noticed another problem when trying to implement Range Requests over a streaming endpoint. The stream data type does not allow to specify a result code, it is always |
|
I managed to fix I'd prefer things which can be separate in separate PRs. |
|
This looks good to me, and what I'd expect. Glad you're doing this! (Also, the response code stuff should def be in a different PR) |
|
Rebased |
|
And CI is green π |
Currently it is not possible to write an instance for
StreamGeneratorfor conduit, despite the comment saying otherwise.Furthermore you cannot use Streams that use a ReaderT IO stack.
This PR trys to solve that
DISCLAIMER: I have to idea what I'm doing