on master help sign in
More documentation on responseStream #262
commit60ff9071254485926c4a911caa7e7543f9a42f67 authorMichael Snoyman <michael@snoyman.com> dateTue 10 Jun 2014, 20:14 (12 years ago) parentf547e52
1 file changed+19
wai/Network/Wai.hs+19
wai/Network/Wai.hs+19
@@ -131,6 +131,25 @@ responseLBS s h = ResponseBuilder s h . fromLazyByteString
131131
132132-- | Creating 'Response' from a stream of values.
133133--
134+-- In order to allocate resources in an exception-safe manner, you can use the
135+-- @bracket@ pattern outside of the call to @responseStream@. As a trivial
136+-- example:
137+--
138+-- @
139+-- app :: Application
140+-- app req respond = bracket_
141+-- (putStrLn "Allocating scarce resource")
142+-- (putStrLn "Cleaning up")
143+-- $ respond $ responseStream status200 [] $ \write flush -> do
144+-- write $ fromByteString "Hello\n"
145+-- flush
146+-- write $ fromByteString "World\n"
147+-- @
148+--
149+-- Note that in some cases you can use @bracket@ from inside @responseStream@
150+-- as well. However, placing the call on the outside allows your status value
151+-- and response headers to depend on the scarce resource.
152+--
134153-- Since 3.0.0
135154responseStream :: H.Status
136155 -> H.ResponseHeaders