Skip to content
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

Fix matchResponseMapWithRequests to handle prompt response. #505

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

bglgwyng
Copy link

@bglgwyng bglgwyng commented Aug 8, 2024

app :: forall t m. (MonadHeadlessApp t m) => m (Event t ())
app = mdo
  ePostBuild <- getPostBuild

  rec (_, eRequest) <-
        runRequesterT
          ( do
              eX <-
                requesting (ePostBuild $> Const ())
              performEvent_ $ ffor eX (const $ liftIO $ print "Got Response!")
          )
          eResponse'
      (eRequest', eResponse') <-
        matchResponseMapWithRequests
          (\x -> (mkSome x, \case Some x -> unsafeCoerce x))
          eRequest
          eResponse
      eResponse <- pure $ ffor eRequest' $ fmap (\(Some req) -> Some (Identity 1))
  pure never

This minimal example demonstrates a request/response interaction. When a request is made, the corresponding response is generated immediately, as seen in the eResponse definition. However, the current implementation of matchResponseMapWithRequests doesn't correctly handle prompt responses, resulting in "Got Response!" not being printed from eX. This fix ensures that prompt responses are handled correctly, allowing "Got Response!" to be printed as expected.

Copy link
Member

@ryantrinkle ryantrinkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good patch, but I am slightly concerned about this being prompt. What if someone does something like this?

b <- requesting a
c <- requesting b

Will that create a cycle? It seems like it would. It would be great to add a test for this

Even if that does in fact create a cycle, we could still have something prompt here as an option

That x -> x
)
outstanding
(snd <$> incoming)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this alignEventWithMaybe invocation is equivalent to mergeWith (flip ()) outstanding (fmap snd incoming)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants