[Haskell-beginners] Nonsensical behavior with http-conduit, httpLbs
cma at bitemyapp.com
Thu Apr 10 05:43:52 UTC 2014
to add to my question adding a delay made it work:
main :: IO ()
main = do
_ <- insertData
myTweet <- queryTweet
On Thu, Apr 10, 2014 at 12:41 AM, Christopher Allen <cma at bitemyapp.com>wrote:
> Repro'd on GHC 7.8.1 and 7.6.3
> Original code is: https://github.com/bitemyapp/bloodhound/
> The code only works if I manually (out of band) run insertData (in a REPL)
> and then run main with the insertData invocation stripped out. If I run
> main with the insertData invocation included, it throws an exception (head)
> because the search results are empty.
> The behavior is as if queryTweet was executing after insertData deleted
> the index, but before it inserted the new data.
> The following is a stripped down example:
> insertData :: IO ()
> insertData = do
> let encoded = encode exampleTweet
> _ <- deleteExampleIndex
> created <- createExampleIndex
> docCreated <- indexDocument (Server "http://localhost:9200") "twitter"
> "tweet" exampleTweet "1"
> print "test"
> return ()
> queryTweet :: IO (Either String Tweet)
> queryTweet = do
> let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)
> <||> IdentityFilter
> let search = Search Nothing (Just queryFilter)
> reply <- searchByIndex testServer "twitter" search
> let result = eitherDecode (responseBody reply) :: Either String
> (SearchResult Tweet)
> let myTweet = fmap (hitSource . head . hits . searchHits) result
> return myTweet
> main :: IO ()
> main = do
> _ <- insertData
> myTweet <- queryTweet
> print myTweet
> further up the call chain, the http call is getting dispatched with
> http-conduit's gear, the result returned with the expression:
> withManager $ httpLbs req
> Included this in case it affects the semantics.
> Can anybody help? This has stumped me for a couple hours and I couldn't
> get anything clueful on IRC.
> Thanks to any that help.
> --- Chris
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners