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

forkAction doesn't work as expected? #55

Open
potocpav opened this issue Oct 17, 2020 · 3 comments
Open

forkAction doesn't work as expected? #55

potocpav opened this issue Oct 17, 2020 · 3 comments

Comments

@potocpav
Copy link

potocpav commented Oct 17, 2020

I need to make AJAX calls in the background which wouldn't be interrupted by GUI events. I tried to use forkAction for this purpose, but it doesn't work as expected. The background request completes, but the resulting event isn't propagated to the calling Widget if any other event occurs in the meantime.

Here is a test-case demonstrating the issue:

module Test.Main where

import Prelude

import Concur.Core (Widget)
import Concur.Core.Patterns (forkAction)
import Concur.React (HTML)
import Concur.React.DOM as D
import Concur.React.Props as P
import Concur.React.Run (runWidgetInDom)
import Control.MultiAlternative (orr)
import Effect (Effect)
import Effect.Aff (Milliseconds(..), delay)
import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect)
import Effect.Class.Console (log)

main :: Effect Unit
main = runWidgetInDom "root" (forkAction computation mainWidget)

computation :: Widget HTML Unit
computation = liftAff (delay $ Milliseconds 2000.0) *> liftEffect (log "sent")

mainWidget :: forall void. Widget HTML Unit -> Widget HTML void
mainWidget comp = do
  ev <- orr
    [ "Click" <$ D.button [P.onClick] [D.text("Click")]
    , "Delay" <$ comp
    ]
  liftEffect $ log $ "received " <> show ev
  mainWidget comp

If I click the button before computation finishes, then Delay is never printed.

I think this used to work fine a year ago, though I am not positive. I wasn't able to build old Concurs to test it.

@srghma
Copy link

srghma commented Jan 30, 2021

yes, the functionality of forkAction is unclear because of the lack of documentation

i.e. the orr function have a race like behavior (when one of the widgets finishes -> other are killed)

but should it kill the forked/remote widget? what is remote widget? unclear

probably the tests should be added for forkAction and remoteWidget

@potocpav
Copy link
Author

potocpav commented Feb 2, 2021

Where should I add the orr? What do you mean by "race like behavior"?

@srghma
Copy link

srghma commented Feb 3, 2021

@potocpav I have updated my comment

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

No branches or pull requests

2 participants