Skip to content

forkAction doesn't work as expected? #55

Open
@potocpav

Description

@potocpav

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions